|
|
发表于 2017-10-8 11:13:15
|
显示全部楼层
好像Python 3 没有实现403,404... 处理。
可以试试http.client
文档链接:https://docs.python.org/3/library/http.client.html#examples
- >>> import http.client
- >>> conn = http.client.HTTPSConnection("www.python.org")
- >>> conn.request("GET", "/")
- >>> r1 = conn.getresponse()
- >>> print(r1.status, r1.reason)
- 200 OK
- >>> data1 = r1.read() # This will return entire content.
- >>> # The following example demonstrates reading data in chunks.
- >>> conn.request("GET", "/")
- >>> r1 = conn.getresponse()
- >>> while not r1.closed:
- ... print(r1.read(200)) # 200 bytes
- b'<!doctype html>\n<!--[if"...
- ...
- >>> # Example of an invalid request
- >>> conn.request("GET", "/parrot.spam")
- >>> r2 = conn.getresponse()
- >>> print(r2.status, r2.reason)
- 404 Not Found
- >>> data2 = r2.read()
- >>> conn.close()
复制代码 |
|