发现一个很棒的壁纸网站,所以我们应该把它爬取下来
内容摘要
发现一个很棒的壁纸网站,所以我们应该把它爬取下来
文章正文
前言
本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理
最近又发现了一个很棒的壁纸网站




环境
- Python3.6
- pycharm
本次目标
爬取网站高清
网站地址
/d/file/p/20221107/pre
爬虫代码
导入工具
import requests import re
请求网站
url = "/d/file/p/20221107/toplist style="color: rgba(128, 0, 0, 1)">".format(page) headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" } response = requests.get(url=url, headers=headers)
解析网站数据
for i in urls: response_2 = requests.get(url=i, headers=headers) img_url = re.findall("<img id="wallpaper" src="(.*?)"", response_2.text, re.S)[0] title = img_url.split("-")[-1] download(title, img_url)
保存数据
def download(title, url): path = "保存地址" + title response = requests.get(url=url) with open(path, mode="wb") as f: f.write(response.content)
代码注释
[!--zhushi--]