1. 程式人生 > >爬取千圖網上的高清圖片

爬取千圖網上的高清圖片

pri highlight compile n) find class retrieve trie ror

貼下源碼

配置環境:python3.5 win10

import urllib.request
import re
#遍歷其中端午節的海報網址頁數 for i in range(1,10): pageurl="http://www.58pic.com/tupian/duanwujie-800-0-"+str(i)+".html" data=urllib.request.urlopen(pageurl).read().decode("utf-8","ignore") #正則表達並不固定只要能找到相同的規律即可!!! pat=‘http://pic.qiantucdn.com/58pic/28/(.*?).jpg!‘ imglist=re.compile(pat).findall(data) for j in range(0,len(imglist)):
#進行異常值處理,防止爬蟲輕易奔潰 try: thisimg=imglist[j] thisimgurl="http://pic.qiantucdn.com/58pic/28/"+thisimg+".jpg!" file="D:/爬蟲/"+str(i)+str(j)+".jpg"
#這裏我存在我D盤爬蟲文件夾下的 urllib.request.urlretrieve(thisimgurl,filename=file) print("第"+str(i)+"頁第"+str(j)+"個圖片爬取成功") except urllib.error.URLError as e: if hasattr(e,"code"): print (e.code) if hasattr(e,"reason"): print (e.reason) except Exception as e: print (e)

  

爬取千圖網上的高清圖片