1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import requests from bs4 import BeautifulSoup import os import time src_list = [] headers = {"User-Agent": '请求头信息'} for i in range(1,3): url = "https://网站地址{}".format(i) response = requests.get(url=url,headers=headers) date = response.text soup = BeautifulSoup(date,"html.parser") for i in range (1,27): src = soup.select("body > div > div.l-body > div.l-layout.l-layout_wide > div > div.content-main > div.wallpapers.wallpapers_zoom.wallpapers_main > ul > li:nth-child("+str(i)+") > a > span.wallpapers__canvas > img") for src in src: src = src.get("src") src = src.replace("300x168","1920x1080") src_list.append(src) count = 0 for src in src_list: count = count+1 response = requests.get(src,headers=headers) date = response.content downlaod ="D:/下载/动漫壁纸/"+time.strftime("%Y_%m_%d_%H_%M_%S")+str(count)+".png" print('成功下载第{}张图片'.format(count)) with open(downlaod,"wb") as f: f.write(date)
|