|
5鱼币
import urllib.request
import os
import random
img_addrs = ['//cdn.huaon.com/images/2022/0209/974cc74222f63b6cb8af667198e1feb6db144761.png?x-oss-process=style/wt750','//cdn.huaon.com/images/2022/0209/a4d5a7f49bce89bab8322a0ff8eb05ed8ac75dc3.png?x-oss-process=style/wt750','//cdn.huaon.com/images/2022/0209/d4adfed092c98bb7c039e38f0ef9fa34ede01c65.png?x-oss-process=style/wt750','//cdn.huaon.com/images/2022/0209/a70a02908b7534286ae7eb2b924c2dd9779a4837.png?x-oss-process=style/wt750']
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')
proxies = ['119.6.144.70:81', '111.1.36.9:80', '203.144.144.162:8080']
proxy = random.choice(proxies)
proxy_support = urllib.request.ProxyHandler({'http':proxy})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url)
html = response.read()
return html
def save_imgs(folder):
for i in range(0,4):
filename = '统计图'+str(i)+'.png'
with open(filename, 'wb') as f:
img = url_open(img_addrs[i])
f.write(img)
def download_mm(folder='OOXX'):
os.mkdir(folder)
os.chdir(folder)
save_imgs(folder)
if __name__ == '__main__':
download_mm()
你的代理好像不能用,所以我注释掉代理那一部分了
import urllib.request
import os
import random
img_addrs = ['http://cdn.huaon.com/images/2022/0209/974cc74222f63b6cb8af667198e1feb6db144761.png?x-oss-process=style/wt750','http://cdn.huaon.com/images/2022/0209/a4d5a7f49bce89bab8322a0ff8eb05ed8ac75dc3.png?x-oss-process=style/wt750','http://cdn.huaon.com/images/2022/0209/d4adfed092c98bb7c039e38f0ef9fa34ede01c65.png?x-oss-process=style/wt750','http://cdn.huaon.com/images/2022/0209/a70a02908b7534286ae7eb2b924c2dd9779a4837.png?x-oss-process=style/wt750'] # 注意这里
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')
# proxies = ['119.6.144.70:81', '111.1.36.9:80', '203.144.144.162:8080']
# proxy = random.choice(proxies)
# proxy_support = urllib.request.ProxyHandler({'http':proxy})
# opener = urllib.request.build_opener(proxy_support)
# urllib.request.install_opener(opener)
response = urllib.request.urlopen(req) # 注意这里
html = response.read()
return html
def save_imgs(folder):
for i in range(0,4):
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()
|
最佳答案
查看完整内容
你的代理好像不能用,所以我注释掉代理那一部分了
|