#python3.4爬網(wǎng)頁圖片### 代碼批量自動下載豆瓣網(wǎng)首頁圖片:``` pythonimport urllib.requestimport retargetDir = 'D:/Photo ' #文件保存路徑if __name__== '__main__': #程序運行入口 weburl = 'http://www.**.com' webheaders = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'} req = urllib.request.Request(url=weburl, headers=webheaders) #構(gòu)造請求報頭 webpage = urllib.request.urlopen(req) #發(fā)送請求報頭 contentBytes = webpage.read().decode('utf-8') imglist=re.findall(r'<img src="([^"]+)"', str(contentBytes)) for each in imglist: filename =targetDir+ each.split('/')[-1] urllib.request.urlretrieve(each, filename,None)```