urllib.request

urllib.request

1、urlopen结果保存在内存。

  

2、ulrretrieve结果保存到文件。

  

3、response有read方法。

  

4、可以创建Request对象。

  

5、发送Post数据,需要encode()成ascii的byte.

  

6、url中加入query

  

7、加入User-Agent参数。

  

8、错误。

  urlopen raises URLError when it cannot handle a response (though as usual with Python APIs, built-in exceptions such as ValueError, TypeError etc. may also be raised).

  HTTPError is the subclass of URLError raised in the specific case of HTTP URLs.

  The exception classes are exported from the urllib.error module.

  

9、http.server.BaseHTTPRequestHandler.responses is a useful dictionary of response codes in that shows all the response codes used by RFC 2616. The dictionary is reproduced here for convenience

  包含所有的HTTP错误码。

  

原文地址:https://www.cnblogs.com/tekkaman/p/5797141.html