import requests
import parsel
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
}
num = 1
for page in range(1,6):
print("\n===============正在获取{}页数据===============".format(page))
url = 'http://www.win4000.com/mobile_2340_0_0_{}.html'.format(page)
resp = requests.get(url,headers=headers)
data = resp.text
html = parsel.Selector(data) # 数据转换
url_list = html.xpath('//div[@class="Left_bar"]//ul[@class="clearfix"]/li/a/@href').extract()
for i in url_list:
resp_2 = requests.get(i,headers=headers).text
html_2 = parsel.Selector(resp_2)
img_url = html_2.xpath('//div[@class="pic-meinv"]/a/img/@src').extract_first()
a = requests.get(img_url,headers=headers).content
name = str(num) + '.png'
print("\t正在下载{}张图片".format(num))
path = r'C:\Users\DELL\Desktop\python_wd\mig\手机壁纸\{}'.format(name)
with open(path,'wb')as f:
f.write(a)
num += 1
09-15
09-15