本帖最后由 zhuangping 于 2021-2-26 14:16 编辑
如有违规请删帖
该网站注册用户还有大尺度图片 兄弟上车
[Python] 纯文本查看 复制代码 import requests,time,random,string
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
urlArr = []
UrlAllArr = []
browser = webdriver.Chrome()
for x in range(1,86):
browser.get("https://wallhaven.cc/search?q=id%3A537&categories=110&purity=100&ratios=16x9&sorting=favorites&order=desc&page="+str(x))
time.sleep(1)
#循环获取每一页的全部图片的页面链接
UrlAllArr = browser.find_elements_by_xpath("/html/body/main/div[1]/section[1]/ul/li")
for xx in range(1,len(UrlAllArr)+1):
urlArr.append(browser.find_element_by_xpath("/html/body/main/div[1]/section[1]/ul/li["+str(xx)+"]/figure/a").get_attribute("href"))
#循环图片url数组并下载
for xxx in urlArr:
browser.get(xxx)
try:
img_url = (browser.find_element_by_xpath("/html/body/main/section/div[1]/img").get_attribute("src"))
#截取后缀名
img_houzhui = img_url.find('.',-6)+1
img_houzhui_str = img_url[img_houzhui:]
#重新命名
img_str = ''.join(random.sample(string.ascii_letters + string.digits,20))+"."+img_houzhui_str
#下载到文件夹
r = requests.get(img_url)
#文件夹路径自行修改
asd = open("C:\\Users\\my\\Desktop\\壁纸\\"+img_str,"wb").write(r.content)
time.sleep(1)
except:
print("失败")
print("抓取完成")
browser.quit()
|