windows下可运行
注意需获取网站源代码
1.打开网页空白处点击右键先择查看页面源代码
2.复制所有
3.在当前文件夹下新建文本文档html.txt
4.打开粘贴保存
5.开始运行程序
暂时没写很复杂的,后期有时间了再写更好玩的
import os
import re
import urllib.request
import gevent
import gevent.monkey
gevent.monkey.patch_all()
num = 0
with open("html.txt", "r", encoding="utf-8") as f:
html_source_code = f.read()
code_list = re.findall(r"https://[^:]*\.jpg", html_source_code)
print("下载的图片数量:%d" % len(code_list))
os.mkdir("img1")
def downloader():
if len(code_list) > 0:
global num
req = urllib.request.urlopen(code_list.pop(0))
jpg = req.read()
with open("img1" + "/" + str(num + 1) + ".jpg", "wb") as f:
f.write(jpg)
num += 1
else:
return
def main():
while True:
gevent.joinall([gevent.spawn(downloader), gevent.spawn(downloader),
gevent.spawn(downloader), gevent.spawn(downloader)])
if len(code_list) <= 0:
break
if __name__ == '__main__':
main()
print("下载完成")
如代码有误可与本人联系