Python's basic approach Requests library functions

A, Requests library of seven commonly used functions:

1. requests.request(method,url,**kwargs)

  • : Method: mode request, the corresponding get / put / post seven kinds
  • : To get the url link page
  • : Access control parameters, a total of 13
  • method: request method

r=requests.request('GET',url,**kwargs)

r=requests.request('HEAD',url,**kwargs)

r = requests.request('POST', url, **kwargs)

r = requests.request('PUT', url, **kwargs)

r = requests.request('PATCH', url, **kwargs)

r = requests.request('delete', url, **kwargs)

r = requests.request('OPTIONS', url, **kwargs)

** kwargs: access control parameter is optional

  • params: byte dictionary or a sequence, as a parameter added to the url
  • data: dictionary, a sequence of bytes or a file object, as the contents of the Request
  • json: JSON-formatted data, as content Request
  • headers: dictionary, HTTP custom header
  • cookies: a dictionary or CookieJar, Request the auth: tuples support HTTP authentication
  • files: a dictionary, file transfer
  • timeout: set the timeout time, seconds
  • proxies: a dictionary, set the access proxy server, you can increase the login authentication
  • allow_redirects: True / False, the default is True, the switch redirects
  • stream: True / False, the default is True, immediately switch access to content download
  • verify: True / False, the default is True, SSL certificate authentication switch
  • cert: Local SSL certificate
  • auth: tuples, support HTTP authentication

2.requests.get(url,params=None,**kwargs)

  • url: url intends to get links to pages

  • params: extra parameters in the url, dictionary or byte stream format, optional

  • ** kwargs: 12 access control parameters

3.requests.head(url,**kwargs)

  • url: url intends to get links to pages

  • ** kwargs: 12 access control parameters (except params)

4. requests.post(url,data=None,json=None,**kwargs)

  • url: url intends to update the page link

  • data: the content of the dictionary, a sequence of bytes or a file, Request of

  • json: content data in JSON format, Request of

  • ** kwargs: 11 access control parameters (in addition to data, json)

5.requests.put(url,data=None,**kwargs)

  •  url: url intends to update the page link

  •  data: the content of the dictionary, a sequence of bytes or a file, Request of

  • ** kwargs: 12 access control parameters (other data)

6.requests.patch(url,data=None,**kwargs)

  • url: url intends to update the page link

  • data: the content of the dictionary, a sequence of bytes or a file, Request of

  • ** kwargs: 12 access control parameters (other data)

7.requests.delete(url,**kwargs)

  • url: url link to the page to be deleted

  • ** kwargs: 13 access control (with 1)

 Second, the property of the Response object

 

 Third, abnormal Requests Library

supplement:

直接携带cookie请求url地址 
1.cookie放在headers中 
2.cookie字典传给cookies参数 
cookie=”….”#通过字典推导式得到 
cookie_dict={i.split(“=”)[0]: i.split(“=”)[1] for i in cookie.split(“;”)} 
requests.get(url,headers=headers,cookies=cookie_dict)

 

先发送post请求,获取cookie,带上cookie请求登陆后的页面 —requests.session() 会话保持 
1.实例化session 
session=requests.session()#此时session实例同requests一样 
2.session.post(url,data,headers)#服务器设置在本地的cookie会被保存在被session中


————————————————
版权声明:本文参考CSDN博主「浩浩江水源源不断流」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42549725/article/details/81012604

 

Guess you like

Origin www.cnblogs.com/qixifly/p/11818926.html