web crawling(plus6) pic mining
Posted 兔子的尾巴_Mini
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web crawling(plus6) pic mining相关的知识,希望对你有一定的参考价值。
#Author:Mini
#!/usr/bin/env python
import urllib.request
import re
import urllib.error
headers=("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)
keyword="连衣裙"
key=urllib.request.quote(keyword)
for i in range(1,101):
try:
url="https://s.taobao.com/search?q="+key+"&imgfile=&js=1&stats_click=search_radio_all%3A1&initiative_id=staobaoz_20171003&ie=utf8&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s="+str(i*44)
data=urllib.request.urlopen(url).read().decode("utf-8","ignore")
pat1=‘"pic_url":"//(.*?)"‘
pic=re.compile(pat1).findall(data)
print("success!")
print(pic)
for j in range(0,len(pic)):
thispic=pic[j]
thispicurl="http://"+thispic
picf="E:/m/"+str(i)+"."+str(j)+".jpg"
urllib.request.urlretrieve(thispicurl,filename=picf)
except urllib.error.URLError as e:
if hasattr(e, "code"):
print(e.code)
if hasattr(e, "reason"):
print(e.reason)
以上是关于web crawling(plus6) pic mining的主要内容,如果未能解决你的问题,请参考以下文章
web crawling(plus2) comment crawling
web crawling(plus5) crawling wechat