介绍
该爬虫可以批量爬取彼岸桌面壁纸图片 页数 延时 爬取地址需要自己修改! 代码也很简单,自己试试吧
站点https://pic.netbian.com
效果
修改方法
修改爬取地址就好了,地址去官方看
地址都是相对应的
文件默认保存D盘image文件夹,自己可以看着改
代码
import re
import time
import requests
import os
headers ={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.190.400 QQBrowser/11.5.5240.400',
}
if not os.path.exists('D:/image/'):
os.mkdir(('D:/image/'))
for page in range(1,100):
url = f'http://pic.netbian.com/4kdongwu/index_{page}.html'
print('\n============''正在爬取第', page, '页============\n')
#打印提示
time.sleep(3)
#延迟
res = requests.get(url=url,headers=headers)
res.encoding =res.apparent_encoding
#编码
# print(res.text)
img_url = re.findall('<a href="/tupian/(.*?).html" target="_blank"><img ',res.text)
#取图片url
# print(img_url)
for img_id in img_url:
# print(img_id)
link = 'http://pic.netbian.com/tupian/'+img_id+'.html'
# print(link)
res1 = requests.get(url=link,headers=headers)
res1.encoding=res1.apparent_encoding
# print(res1.text)
data2=re.findall('<img src="(.*?)" ',res1.text)[0]
img_title =re.findall('<h1>(.*?)</h1>',res1.text)[0]
img_url='http://pic.netbian.com'+data2
image =requests.get(url=img_url,headers=headers).content
with open('D:/image/'+img_title+'.jpg',mode='wb')as f:
f.write(image)
print(img_title,img_url)
评论 (0)