[Python] Basic use of Requests library

Official Chinese document: https://requests.readthedocs.io/zh_CN/latest/

Installation :

pip install requests

Case :
The following case is in the official document:

>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200

>>> r.headers['content-type']
'application/json; charset=utf8'

>>> r.encoding
'utf-8'

>>> r.text
u'{"type":"User"...'

>>> r.json()
{
    
    u'private_gists': 419, u'total_private_repos': 77, ...}

methods of the requests library

The requests library mainly has the following 7 methods

method Explanation
requests.request() Construct a request to support the following methods
requests.get() The main method of obtaining html
requests.head() The main method of obtaining HTML header information
requests.post() Method for submitting post request to html page
requests.put() Method for submitting put request to html webpage
requests.patch() Submit partial modification request to html
requests.delete() Submit a delete request to html

Guess you like

Origin blog.csdn.net/weixin_45468845/article/details/108493826