Python3 21.6. urllib.request 常用方法中文翻译(自翻)

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_24076135/article/details/77971200

request 是一个帮助打开url(大多数为http)的方法.

The urllib.request module defines the following functions:

urllib.request 定义了以下的方法:

urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=False, context=None)

参数:
- url:目标路径 可以使str或者是request对象
- data[默认为None]:指定的额外发送给server的data对象.如果没有这样的data要求,则为None
- timeout[可选参数]:明确阻塞操作(比如connection attempt)的超时时间.如果没明确,则会使用全局默认超时间,该参数实际只在HTTP, HTTPS and FTP 连接中有效.
- context[默认为None]:必须是 ssl.SSLContext的实例
- cafile[默认为None]:和capath 指定了HTTPS requests的可信任CA证书.指向了一个包含一捆CA证书的文件
- capath[默认为None]:指向了可信任CA证书的目录或hash .
- cadefault:该参数被忽略了……

urllib.request模块使用的 HTTP/1.1

This function always returns an object which can work as a context manager and has methods such as

该方法总是返回一个能作为context manager的对象,并且有以下操作:
- geturl() — 返回一个资源检索的URL,一般被用来判断是否存在重定向.
- info() — 返回页面的meta信息
- getcode() – return the HTTP status code of the response.返回返回的http状态码,如果返回200表示请求成功

猜你喜欢

转载自blog.csdn.net/qq_24076135/article/details/77971200
今日推荐