1. 程式人生 > >使用 requests 模組

使用 requests 模組

官網:http://docs.python-requests.org/en/master/

請求方式

requests.get()

requests.post()

requests.put()

requests.delete()

requests.head()

requests.options()

get請求:

requests.get(url, **kwargs)

引數:

method:

url:

params: 預設 None           Dictionary or bytes to be sent in the query string        get請求的url引數

data: 預設 None                Dictionary or bytes to send in the body                        post請求的請求體

headers: 預設 None          Dictionary of HTTP Headers to send                            請求頭

cookies: 預設 None           Dict or CookieJar object to send                                   請求cookies

files: 預設 None                 Dictionary of ``'filename': file-like-objects`` for multipart encoding upload            put請求上傳檔案

auth: 預設 None                 Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth 

timeout: 預設 None            How long to wait for the server to send data before giving up, as a float, or a (`connect timeout, read timeout <user/advanced.html#timeouts>`_) tuple.   請求超時時間

allow_redirects: 預設 True

proxies: 預設 None            Dictionary mapping protocol to the URL of the proxy.      代理

hooks: 預設 None

stream: 預設 None            Whether to immediately download the response content. Defaults to ``False``   是否立即下載響應內容

verify: 預設 None               if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.

cert: 預設 None                 if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.

json: 預設 None                json to send in the body                               put請求體

未完待續