欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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) 

python爬虫爬取彼岸和wallhaven壁纸

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 

python爬虫爬取彼岸和wallhaven壁纸
这就很nice
python爬虫爬取彼岸和wallhaven壁纸

本文地址:https://blog.csdn.net/weixin_44772112/article/details/109023988

相关标签: python爬虫