Web crawling (PLUS6) pic mining

Source: Internet
Author: User

#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= "Dress"
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.