一:原创,过程可能较重复,但实现逻辑简单:
整个爬取逻辑:从一个页面跳转到另一个页面再获取(高清无损)壁纸的具体网址,然后下载就可。
二:用到的模块:requests,beautifulsoup模块*
***三:具体实现代码(完整可直接使用)***:
import re
import requests
import time#####
from bs4 import BeautifulSoup
from lxml import etree
headers={
"User-Agent":"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36"
}
url="http://www.netbian.com/1920x1080/index_3.htm"
main_page=requests.get(url=url,headers=headers)
main_page.encoding=main_page.apparent_encoding
soup=BeautifulSoup(main_page.text,"lxml")
li_list=soup.select(".list li>a")
for li in li_list:
li_herf=li["href"]
the_real="http://www.netbian.com/"+li_herf
response=requests.get(url=the_real,headers=headers)
response.encoding=response.apparent_encoding
real_soup=BeautifulSoup(response.text,"lxml")
img=real_soup.select(".pic img")[0]["src"]#获得图片网址
img_resp=requests.get(url=img,headers=headers)#request解析
img_name=img.split("/")[-1]#根据具体而修改
# print(img_name)
# print(img)
with open("bian/"+img_name,mode="wb")as f:
f.write(img_resp.content)#不需要修改
print("over",img_name)
time.sleep(1)#防被服务器检测禁止ip访问