这篇文章主要介绍了python如何爬取壁纸网站数据,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
前言
本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理
最近又发现了一个很棒的壁纸网站


![]()
环境
Python3.6
pycharm
本次目标
爬取网站高清
网站地址
https://wallhaven.cc/
爬虫代码
导入工具
import requests
import re
请求网站
url = 'https://wallhaven.cc/toplist?page={}'.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">
保存数据
def download(title, url):
path = '保存地址' + title
response = requests.get(url=url)
with open(path, mode='wb') as f:
f.write(response.content)
感谢你能够认真阅读完这篇文章,希望小编分享的“python如何爬取壁纸网站数据”这篇文章对大家有帮助,同时也希望大家多多支持天达云,关注天达云行业资讯频道,更多相关知识等着你来学习!