Python爬取精美壁紙,附源碼

import reimport requestsimport os
url = 'https://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word=='+name+'+&pn='+str(i*30)result = requests.get(url,headers=headers)dowmloadPic(result.content.decode(), name)
pic_url = re.findall('"objURL":"(.*?)",',html,re.S)
fp = open(dir, 'wb')fp.write(pic.content)fp.close()
#!/usr/bin/python# -*- coding: UTF-8 -*-import reimport requestsimport osdef dowmloadPic(html, keyword,i):pic_url = re.findall('"objURL":"(.*?)",',html,re.S)abc=i*60print('找到關(guān)鍵詞:' + keyword + '的圖片,現(xiàn)在開始下載圖片...')...完整代碼:請移步到,公眾號:詩一樣的代碼dir = r'D:\image\i' + keyword + '_' + str(abc) + '.jpg'if not os.path.exists('D:\image'):os.makedirs('D:\image')fp = open(dir, 'wb')fp.write(pic.content)fp.close()abc += 1if __name__ == '__main__':#word = input("Input key word: ")headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36'}name = input('輸入下載圖片的名字')num = 0x = input('您要爬取幾張呢?,n*60')for i in range(int(x)):url = 'https://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word=='+name+'+&pn='+str(i*30)result = requests.get(url,headers=headers)dowmloadPic(result.content.decode(), name,i)print("下載完成")
搜索下方加老師微信
老師微信號:XTUOL1988【切記備注:學(xué)習(xí)Python】
領(lǐng)取Python web開發(fā),Python爬蟲,Python數(shù)據(jù)分析,人工智能等精品學(xué)習(xí)課程。帶你從零基礎(chǔ)系統(tǒng)性的學(xué)好Python!
*聲明:本文于網(wǎng)絡(luò)整理,版權(quán)歸原作者所有,如來源信息有誤或侵犯權(quán)益,請聯(lián)系我們刪除或授權(quán)
評論
圖片
表情



