Python crawler Learning

Source: Internet
Author: User

Crawler, how should the notes be written?

Standard Style

This is a standard style, r=requests.request (Get,params, and other parameters), parameters are headers, is user_agent, is the user agent, the default this is Python requests, but some sites do not support, Like Amazon. So we have to add User agent parameters, (can be replaced by the Google browser to open user interface, there is.) Also downloaded a plugin user_agent switcher, want to change what kind of can.

1 ImportRequests2 ImportOS3Root ='d://pics//'4Url='http://www.nationalgeographic.com.cn/photography/photo_of_the_day/4309.html'5Path = root + Url.split ('/') [-1]6 Try:7     if  notos.path.exists (Root):8 Os.mkdir (Root)9     if  notos.path.exists (path):TenR=requests.get (URL) OneWith open (path,'WB') as F: A f.write (r.content) - f.close () -             Print('file saved successfully') the     Else: -         Print('file already exists') - except: -     Print('Crawl failed')
Climb a picture

I still don't understand this, and I didn't crawl out.

Python crawler Learning

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.