多多点赞 不要客气
import urllib.request
import gevent
import re
from gevent import monkey
monkey.patch_all()
def get_url(url):
req = urllib.request.Request(url)
page = urllib.request.urlopen(req)
html = page.read()
file = open("b.txt", "wb")
file.write(html)
file.close()
def download(img_name, img_url):
req = urllib.request.urlopen(img_url)
img_content = req.read()
# 这是要保存地址的路径
file = open("D:/python基础/yang_02/patu/65120/" + img_name, "wb")
file.write(img_content)
file.close()
def main(url):
get_url(url)
with open("b.txt", "rb") as f:
str1 = f.read()
print(str1)
# 正则表达式
img_ls = re.findall(r"https://huyaimg.*?\.jpg", str(str1))
print(img_ls)
cut = 501
for i in img_ls:
# 定义变量 每次+1 当作图片的名字
count = ("%s" + ".jpg") % cut
gevent.joinall([
gevent.spawn(download, count, i)
])
cut += 1
if __name__ == '__main__':
main("https://www.huya.com/g/2633")