import requests
from pyquery import PyQuerycount = 1url = "https://www.169tp.com/diannaobizhi/"headers = { 'User-Agent': ' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'}res = requests.get(url).content.decode('gbk')doc = PyQuery(res)
jiexi = doc('.product011 li a').items()for i in jiexi: data_url = i.attr('href') data_title = i.attr('alt')# print(data_title, data_url)img_url = requests.get(data_url).content.decode('gbk')
doc2 = PyQuery(img_url) nier = doc2('.big_img p img').items() for k in nier: img = k.attr('src')neirong =requests.get(img)
with open('./电脑壁纸/壁纸{}.jpg'.format(count),'wb') as f: f.write(neirong.content) print("已经下载了%d张图片"%(count)) count +=1