python3 http.client我不能用于非www站点

时间:2018-02-23 13:05:32

标签: python urllib http.client

我想查看此网站是否在线。

import http.client
c = http.client.HTTPConnection("https://support.binance.com/hc/en-us/categories/115000056351")
c.request("HEAD", "/index.html")
print (c.getresponse().status)

代码适用于

c = http.client.HTTPConnection("www.google.com")

1 个答案:

答案 0 :(得分:1)

您可以尝试使用requests。如果状态代码为200,则表示该站点在线

In [20]: import requests

In [21]: req = requests.get('https://support.binance.com/hc/en-us/categories/115000056351')

In [22]: req
Out[22]: <Response [200]>