A path to the python reptile of salted fish (i): Requests Library

Source: Internet
Author: User

As a salted fish University played 3 years of game just waking wake up, and now began to learn something, here to record their own learning.

Urllib Library before some understanding will not write, starting from the requests library (ˉ▽ ̄~).

The first thing to say is be sure to use the Official document: http://docs.python-requests.org/en/master/

Let's look at a column first:

Here are some basic uses of the requests library:

The specific code is just a little over the official documentation exercise, which is the most commonly used method.

The Response object contains all the information returned by the server and also contains the request information for the requests.

Property

Give the code for a standard crawl page:

1 ImportRequests2 3 defgeturl (URL):4    Try:5R=requests.get (url,timeout=100)6 r.raise_for_status ()7R.encoding=r.apparent_encoding#replacement Code Some Web page guessing code will error8        returnR.text9    except:Ten        return "Exception" One  A  - if __name__=="__main__": -Url="http://jwweb.scujcc.cn/" the     Print(Geturl (URL))

The code is given to our school's academic Web site if you do not r.apparent_encoding replacement r.enconding will report the encoding error you can try it.

First write this also no idea big guy light spray, content after a new understanding will also add in slowly improve also hope that we give some advice.

A path to the python reptile of salted fish (i): Requests Library

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.