前言

本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理

最近又发现了一个很棒的壁纸网站

 

 

 

 

环境

  • 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" 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)

 

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/hhh188764/p/13869265.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!