使用 requests 模块

时间:2022-12-07 22:32:57

官网: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请求体

未完待续