import urllib.request
import os
a = 'https://cdn.huaon.com/images/2022/0209/974cc74222f63b6cb8af667198e1feb6db144761.png?x-oss-process=style/wt750'
b = 'https://cdn.huaon.com/images/2022/0209/a4d5a7f49bce89bab8322a0ff8eb05ed8ac75dc3.png?x-oss-process=style/wt750'
c = 'https://cdn.huaon.com/images/2022/0209/d4adfed092c98bb7c039e38f0ef9fa34ede01c65.png?x-oss-process=style/wt750'
d = 'https://cdn.huaon.com/images/2022/0209/a70a02908b7534286ae7eb2b924c2dd9779a4837.png?x-oss-process=style/wt750'
e = 'https://cdn.huaon.com/images/2022/0210/efbd4dbee868df1419eb63f05b2f7db351109df6.png?x-oss-process=style/wt750'
f = 'https://cdn.huaon.com/images/2022/0210/b5a1329e58424f58f548293e3666d5dc55f5217d.png?x-oss-process=style/wt750'
g = 'https://cdn.huaon.com/images/2022/0210/78e857f7afec592a4c6f6e26cc2d6f5ee9c25349.png?x-oss-process=style/wt750'
h = 'https://cdn.huaon.com/images/2022/0210/60aec57a50e9721172a92876dccaed9bb87ecbfb.png?x-oss-process=style/wt750'
img_addrs = [a,b,c,d,e,f,g,h]
def url_open(url):
req = urllib.request.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 SLBrowser/8.0.0.4153 SLBChan/105')
response = urllib.request.urlopen(req)
html = response.read()
return html
def save_imgs(folder):
for i in range(0,8):
filename = '统计图'+str(i)+'.png'
with open(filename, 'wb') as f:
img = url_open(img_addrs[i])
f.write(img)
def download_mm(folder='OOXX'):
if not os.path.exists(folder):
os.mkdir(folder)
os.chdir(folder)
save_imgs(folder)
if __name__ == '__main__':
download_mm()
如果网站对访问频率做了限制,要么用 sleep 使执行过程不那么快,
要么就用代理
|