标签:response htm with open turn open image write nbsp 目标
目标:汽车之家https://car.autohome.com.cn/pic/series/153-1-p5.html
#!/urs/bin/evn python # -*- coding:utf-8 -*- import requests import re def get_url(url): response = requests.get(url) response.encoding = "gb2312" r = ‘<img src="(.*?)" alt=".*?">‘ url_list = re.findall(r, response.text) return url_list def get_jpg(url, name): response = requests.get(url) response.encoding = "gb2312" with open(r"D:\data\%d.jpg" % name, "wb") as ft: ft.write(response.content) if __name__ == ‘__main__‘: a = 1 for i in range(1, 6): url_list = get_url("https://car.autohome.com.cn/pic/series/153-1-p%d.html" % i) for url in url_list: com_url = "http:" + url get_jpg(com_url, a) a += 1
标签:response htm with open turn open image write nbsp 目标
原文地址:https://www.cnblogs.com/zqxqx/p/9314148.html