Skip to content

网站下载到本地

经常访问 VTK 或其他网站的教程时,如果不使用 SSR,可能会非常卡,甚至打不开。为了方便以后查询,我决定把整个教程网站下载到自己的服务器上。

以下是下载网站并进行简单处理的示例:

wget -r -p -np -k https://doc.cgal.org/latest/Manual/general_intro.html

对于下载的 VTKExamples,需要进行如下简单处理:将所有指向 ".1" 后缀的文件名修改为 ".html",并将外部链接修改为本地链接,以防止未来访问卡顿。

import os

# 替换文件名后缀
for root, dirs, files in os.walk(".", topdown=True):
    for name in files:
        filename = os.path.join(root, name)
        portion = os.path.splitext(filename)
        if portion[1] == '.1':
            newname = portion[0] + '.html'
            os.rename(filename, newname)

# 替换文件中的链接
for root, dirs, files in os.walk(".", topdown=True):
    for name in files:
        filename = os.path.join(root, name)
        if filename.endswith('.html'):
            with open(filename, "r") as f:
                content = f.read()
            # 替换链接
            updated_content = content.replace('.1"', '.html"').replace('https://lorensen.github.io/VTKExamples/site/', '1ip/VTKExamples/site/')
            with open(filename, "w") as f:
                f.write(updated_content)

这样处理后,你可以将整个网站挂在自己的服务器上浏览,方便随时查询和学习。