您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“Python如何爬取高清4K桌面壁紙”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Python如何爬取高清4K桌面壁紙”這篇文章吧。
目標(biāo)網(wǎng)址:
http://www.netbian.com/
部分代碼
導(dǎo)入工具
import requests import parsel
請(qǐng)求網(wǎng)站數(shù)據(jù)
url = 'http://www.netbian.com/index_2.htm' cookies = { 'Cookie': '__cfduid=d892faf2d87d3fd9bd75b5606165cd68c1598431866; Hm_lvt_14b14198b6e26157b7eba06b390ab763=1598431867,1598516099; xygkqecookieinforecord=%2C12-22800%2C19-22803%2C12-22835%2C19-22699%2C19-22649%2C19-22775%2C; Hm_lpvt_14b14198b6e26157b7eba06b390ab763=1598516285' } 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', 'Referer': 'http://www.netbian.com/' } response = requests.get(url=url, headers=headers, cookies=cookies) response.encoding = response.apparent_encoding
解析數(shù)據(jù)
selector = parsel.Selector(response.text) lis = selector.css('.list ul li a::attr(href)').getall() # print(lis) lis.pop(2) lis.pop(2) # 想要完整源碼的同學(xué)可以關(guān)注我的公眾號(hào):松鼠愛吃餅干 # 回復(fù)“壁紙”即可免費(fèi)獲取
保存數(shù)據(jù)
path = 'C:\\Users\\Administrator\\Desktop\\彼岸\\' + title + '.jpg' with open(path, mode='wb') as f: f.write(img_url_response.content) print('{}已經(jīng)下載完'.format(title))
運(yùn)行代碼,效果如下圖
以上是“Python如何爬取高清4K桌面壁紙”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。