前言
本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,著作權歸原作者所有,如有問題請及時聯系我們以作處理
最近又發現了一個很棒的壁紙網站
環境
- 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="https://www.cnblogs.com/hhh188764/archive/2020/10/24/(.*?)"', 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.uj5u.com/houduan/188893.html
標籤:其他
