最近啊,有些人總是喜歡亂點一些七七八八的網站,沒錯,就是那個巳月,點完了又喊我爬,自己不爬!
就是這些,眼熟嗎,反正我一個不認識!!

一開始我是嚴詞拒絕的!我是那樣的人嗎?要不是他請我喝奶茶讓我來,我才不瞎搞呢!

軟體環境
- Python 3.8 解釋器
- Pycharm 編輯器
模塊使用
- requests 資料請求模塊
- re 正則
代碼展示
代碼僅做展示
import requests import re # Python學習交流群 708525271 更多案例獲取 for page in range(1, 11): url = f'https://wallhaven.cc/search?q=id%3A65348&sorting=random&ref=fp&seed=UGMZnc&page={page}' headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36' } response = requests.get(url=url, headers=headers) # print(response.text) href = https://www.cnblogs.com/hahaa/archive/2022/10/18/re.findall('<a href="https://www.cnblogs.com/hahaa/archive/2022/10/18/(.*?)"', response.text) print(href) for link in href: html_data = requests.get(url=link, headers=headers).text print(html_data) img_info = re.findall('<img id="wallpaper" src="https://www.cnblogs.com/hahaa/archive/2022/10/18/(.*?)" alt="(.*?)"', html_data) img_content = requests.get(url=img_info[0][0], headers=headers).content # 二進制資料內容 with open('img\\' + img_info[0][1] + '.jpg', mode='wb') as f: f.write(img_content)
效果演示
因為咱是個正經的人,所以我下載的都是正經的,至于嗯啊嗯自己發掘吧~
最后分享一套Python教程,涵蓋大部分的案例實戰,希望對大家有所幫助:代碼總是學完就忘記?100個Python實戰專案!讓你沉迷學習丨學以致用丨下一個Python大神就是你!

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/517529.html
標籤:其他
上一篇:R語言、03 案例3-3 亞太地區商學院、《商務與經濟統計》案例題
下一篇:C語言簡易計算器
