前言
本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,如有問題請及時聯系我們以作處理,
PS:如有需要Python學習資料的小伙伴可以加點擊下方鏈接自行獲取
python免費學習資料以及群交流解答點擊即可加入
基本環境配置
- python 3.6
- pycharm
- requests
- parsel
相關模塊pip安裝即可
確定網址
https://www.huya.com/g/2168


請求網頁
import requests
url = 'https://www.huya.com/g/2168'
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)
print(repsonse.text)
決議網頁資料
import parsel
selector = parsel.Selector(response.text)
urls = selector.css('.live-list .game-live-item a img::attr(data-original)').getall()
titles = selector.css('.live-list .game-live-item a img::attr(title)').getall()
info_data = zip(urls, titles)
for i in info_data:
img_url = i[0].split('?')[0]
title = i[1]
保存資料
img_url_response = requests.get(url=img_url, headers=headers)
path = 'D:\\python\\demo\\虎牙\\img\\' + title + '.jpg'
with open(path, mode='wb') as f:
f.write(img_url_response.content)
print(title)
實作效果






轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/161521.html
標籤:其他
上一篇:—用python寫截屏小工具
