python爬虫爬取彼岸和wallhaven壁纸
程序员文章站
2022-05-05 09:32:56
最近在设置pycharm背景板的时候,想找一些好看的壁纸,记录一下吧彼岸壁纸代码(彼岸是每天只能下载一张的,我曾在嫉妒愤怒的情况下。。。)import requestsfrom lxml import etreeheader = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36',...
最近在设置pycharm背景板的时候,想找一些好看的壁纸,记录一下吧
彼岸壁纸代码(彼岸是每天只能下载一张的,我曾在嫉妒愤怒的情况下。。。)
import requests from lxml import etree
header = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36', 'cookie':'__cfduid=d87f516a21ea92ec0ae00ab0138eb602f1601093627; Hm_lvt_2c6cc9163dcd6f496c48a6b8ac043309=1601093627,1601093653; Hm_lpvt_2c6cc9163dcd6f496c48a6b8ac043309=1601093668', } for k in range(2,10): res = requests.get('http://www.4kbizhi.com/meinv/index_'+str(k)+'.html',headers=header) res.encoding=res.apparent_encoding
html = etree.HTML(res.text) img = html.xpath('/html/body/div[2]/div[1]/ul/li/a/img/@src') title=html.xpath('/html/body/div[2]/div[1]/ul/li/a/p/text()') for i in range(len(img)): url='http://www.4kbizhi.com'+img[i] with open("data/彼岸/"+title[i]+".jpg", "wb") as f: f.write(requests.get(url).content)
wallhaven壁纸代码(这是个外国网站)
import requests from fake_useragent import UserAgent import re from lxml import etree
header={"User-Agent":(str(UserAgent().random))} number=0 for j in range(1,10): url = 'https://wallhaven.cc/search?q=id%3A5&sorting=random&ref=fp&seed=jYVlG&page='+str(j) response = requests.get(url,headers=header) html = etree.HTML(response.text) first_url=html.xpath('//*[@id="thumbs"]/section[1]/ul/li/figure/a/@href') for i in first_url: result=requests.get(i, headers=header) img_url=re.findall('id="wallpaper" src="(.*?)"',result.text) with open("data/wallhaven壁纸/"+"小妹妹"+str(number)+".jpg", "wb") as f: f.write(requests.get(img_url[0], headers=header).content) number+=1
这就很nice
本文地址:https://blog.csdn.net/weixin_44772112/article/details/109023988
上一篇: 火锅底料需不需要炒了再煮
推荐阅读
-
【Python爬虫案例学习】Python爬取淘宝店铺和评论
-
python3爬虫-快速入门-爬取图片和标题
-
python爬虫爬取彼岸和wallhaven壁纸
-
Python爬虫 爬取彼岸桌面壁纸 netbian 1920x1080
-
python爬虫学习之爬取超清唯美壁纸
-
【Python Scrapy 爬虫框架】 5、利用 pipelines 和 settings 将爬取数据存储到 MongoDB
-
Python爬虫:爬取带隐藏域__EVENTVALIDATION和__VIEWSTATE的form提交网页
-
python 爬虫一键爬取 淘宝天猫宝贝页面主图颜色图和详情图的教程
-
Python3爬虫爬取百姓网列表并保存为json功能示例【基于request、lxml和json模块】
-
Python3实现爬虫爬取赶集网列表功能【基于request和BeautifulSoup模块】