这是老站内容!

前言

这是我一年多前开的坑了。那时我刚学了点 C++、python 的皮毛,就想着赶紧应用一下。碰巧那时我为了准备语文课前演讲去下载了一些 HTML 模板,还找模板做了个人主页,就想要把网站上的那些 HTML 模板打包下来。那时我还在用老 WordPress 博客,现在算是不想去支付高昂的开服费用来重新开启它了。碰巧我在妈妈的笔记本电脑上发现那时用的 Edge 浏览器还有缓存,就想着赶紧把那时懵懂的高二写的一些文章陆陆续续地搬到我现在的博客上来,重新组织下语言。

老博客一瞥

网站

要被遍历 URL 的网站是 www.mobanwang.com

要知道“模板”的正确拼法是“mú bǎn”。

URL(原始)

模板王网站的文件原始下载链接格式:

1
http://www.mobanwang.com/mb/showsoftdown.asp?urlid=1&softid=数字(如 18257)

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
int main()
{
int id=0,n=30000;
while(id<=n)
{
std::cout<<
"http://www.mobanwang.com/mb/showsoftdown.asp?urlid=1&softid="
<<id<<std::endl;
++id;
}
return 0;
}

用 C++ 编译器把上方代码编译成 .exe 文件,然后在该文件目录的 Windows 终端里输入 test.exe > test.txt 保存输出。

找个能批量下载链接的应用,比如 IDM 和 Chrome + 插件 Chrono,输入 .text 文件的内容进行下载。

如果想要遍历网站资源,可以用 Linux 命令 wget -r -p -U Mozilla [url]。但是这对模板王网站无效,因为访问该站存放模板的目录会被拒绝。

URL(重定向)

模板王网站的文件重定向后的下载链接格式如:

1
http://www.mobanwang.com/mb/UploadFiles_2010/lo202102/202102029.rar

或:

1
http://www.mobanwang.com/mb/UploadFiles_2010/myup200702/200702050.rar

可以发现规律:

  1. 前缀:lo 或者 myup
  2. 年月:如 202102
  3. 编号:如 202102029(.rar)

python

vim old.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
idCounter = 1
M = 1
before = input("前缀(lo 或者 myup):")
Y = int(input("起始年(如 2010):"))
endY = int(input("终止年(如 2022):"))
endID = int(input("最大 id(不超过三位数):"))
log = open(r"D:/now.sh", "a+")
while Y <= endY:
YM = Y * 100 + 1
YMID = YM * 1000 + 1
while M <= 12:
print(f"wget http://www.mobanwang.com/mb/UploadFiles_2010/{before}{YM}/{YMID}.rar | tr -d '\r'", file=log)
YMID = YMID + 1
idCounter = idCounter + 1
if idCounter > endID:
YM = YM + 1
M = M + 1
idCounter = 1
YMID = YM * 1000 + 1
else:
Y = Y + 1
M = 1
else:
log.close()

如果是 Windows,确保已经安装 Python,在该文件目录的 Windows 终端里输入 python old.py

然后在 D 盘找到 now.sh,扔进 Linux 里执行即可。


现在,ChatGPT 给出了一个更优的方案:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def output_url(prefix, start_year, end_year, start_month, end_month, end_id_number):
with open("yes.sh", "w") as f:
for year in range(start_year, end_year+1):
for month in range(start_month, end_month+1):
month_str = str(month).zfill(2)
for id_number in range(1, end_id_number+1):
id_number_str = str(id_number).zfill(3)
f.write("wget http://www.mobanwang.com/mb/UploadFiles_2010/" + prefix + str(year) + month_str + "/" + str(year) + month_str + id_number_str + ".rar\n")

prefix = input("请输入前缀(lo 或 myup):")
start_year = int(input("请输入开始年份(如 2020):"))
end_year = int(input("请输入结束年份(如 2023):"))
start_month = int(input("请输入开始月份(如 1,自然数):"))
end_month = int(input("请输入结束月份(如 12,自然数):"))
end_id_number = int(input("请输入最大编号(如 300):"))

output_url(prefix, start_year, end_year, start_month, end_month, end_id_number)