web crawling(plus6) pic mining
阿新 • • 發佈:2017-10-03
header decode compile ror head ucc err fse cli
#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