python爬取三国杀咨询网站的新皮肤
生活随笔
收集整理的這篇文章主要介紹了
python爬取三国杀咨询网站的新皮肤
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在家無事做看三國殺皮膚畫的不錯,就隨性爬取下來
# 爬取三國殺圖片 from urllib.request import urlopen from urllib.parse import urljoin from re import findall,S from os.path import basenameurl = 'https://www.sanguosha.com/Home/newsInfo/a_id/20200109_7406_4617' while True:try:with urlopen(url) as fp:content = fp.read().decode('utf-8')result = findall(r'新品皮膚一覽.*?下一篇.*?/div>', content, S) resultpic = findall(r'<img src="(.*?)"', str(result))if resultpic!=[]:for picurl in resultpic:picurl = urljoin(url, picurl)with urlopen(picurl)as fd:with open('C://Users//Administrator//Pictures'+'//'+basename(picurl), 'wb') as fp:fp.write(fd.read())url = str(findall(r'下一篇.*?href="(.*?)"',content, S)[0])print(url)except:break但是有個問題三國殺最后一頁仍有下一篇,不會自己停止,運行一會手動停了吧!
總結
以上是生活随笔為你收集整理的python爬取三国杀咨询网站的新皮肤的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jsp作业--计算矩形、圆形面积
- 下一篇: 使用PageOffice实现文档(wor