Simple to use python requests of

1. Import requests library

Into the dos command-line installation requets library by pip command

pip install requests

2. The first simple example

First, we should import requets library

import requests
r = requets.get("http://www.baidu.com")

By type (r) we find requests.get () method returns Response

<class 'requests.models.Response'>

Next we see what text

import requests
r = requets.get("http://www.baidu.com")

r.text

We will find that this time there will be a lot of garbage, because the problem is coded, this time type checking code r

import requests
r = requets.get("http://www.baidu.com")

r.text

r.encoding

At this point we will find default encoding: 'ISO-8859-1' form
then we will modify the modified encoded form as r 'utf-8' form

At this point in the text to read you will find you can read normal

import requests
r = requets.get("http://www.baidu.com")

r.text

r.encoding

r.encoding = 'utf-8'

r.text

Guess you like

Origin www.cnblogs.com/wlw-x/p/12333975.html