Don't you want to know how to crawl a sexy beauty wallpaper with Python?

Source: Internet
Author: User

Baidu Sexy Beauty Wallpaper look

See this picture, there is no kind of ..... emmmmm ... A feeling of irritation and excitement

Whether or not you have a small part of me is a momentum, since the Python crawler know, as long as you see a sister's photos of the site, I just want to bulk download!

Not for anything else, to be able to learn python! better. Do you believe me when I say that?

Get ready:

Python3.6

Import requests

Import JSON

Full code
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4 ImportRequests5 ImportJSON6 7 8 #define a request function, receive page parameters9 defget_page (page):Ten     #Add the page parameter to the URL string OneURL ='Https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result &queryword= Beauty &cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=-1&z=&ic=0&word = Beauty &s=&se=&tab=&width=&height=&face=0&istype=2&qc=&nc=1&fr=&cg= GIRL&PN={}&RN=30&GSM=1E'. Format ( A page) -     #Request a Web site and get a response from the website -     #Python Learning Exchange Group: 125240963, the group to share the daily dry, including the latest Python enterprise case study materials and 0 basic introductory tutorials, welcome to the group of small partners to learn exchange theResponse =requests.get (URL) -     #determine the state of the condition -     ifResponse.status_code = = 200: -         #return text file information +         returnResponse.text -  +  A defjson_load (text): at     #to process a text file into a dictionary format -Jsondict =json.loads (text) -     #Create an empty collection, the function is to go to the heavy -Urlset =set () -     #Check if the dictionary contains the value of data -     if 'Data' inchJsondict.keys (): in         #Extract the contents of data from the jsondict in the dictionary, and then assign the value to items! -          forItemsinchJsondict.get ('Data'): to             #exception handling, not every row of data contains thumburl this data +             Try: -Urlset.add (items['Thumburl']) the             except: *                 Pass $     returnUrlsetPanax Notoginseng  -  the defdown_cont (URL): +Response =requests.get (URL) AName = Url.split (',') [ -1].split ('&') [0] the     ifResponse.status_code = = 200: +         #indicates that if the file name is the same, delete the current file and then create a file of the same name -With open ('./images/%s.jpg'% Name,'WB') as F: $             Print('downloading current Picture:'+URL) $             #writes to the local by binary method - f.write (response.content) -  the  - defMain ():Wuyi      forPinchRange (5): the         Print('downloading picture of%s page'%p) -page = p * 30 WuText =get_page (page) -Urlset =json_load (text) About          forUrlinchUrlset: $ down_cont (URL) -  -  - if __name__=='__main__': AMain ()
Run results

Don't you want to know how to crawl a sexy beauty wallpaper with Python?

Related Article

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.