通过Python检查网站是否已启动 [英] Checking if a website is up via Python
本文介绍了通过Python检查网站是否已启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过使用python,如何检查网站是否已启动?根据我的阅读,我需要检查HTTP HEAD并查看状态代码200 OK,但该怎么做?
By using python, how can I check if a website is up? From what I read, I need to check the "HTTP HEAD" and see status code "200 OK", but how to do so ?
干杯
- How do you send a HEAD HTTP request in Python?
推荐答案
您可以尝试从 getcode()执行此操作//docs.python.org/library/urllib.html\"rel =noreferrer> urllib
You could try to do this with getcode()
from urllib
>>> print urllib.urlopen("http://www.stackoverflow.com").getcode()
>>> 200
编辑:更现代的python,即 python3
,使用:
For more modern python, i.e. python3
, use:
import urllib.request
print(urllib.request.urlopen("http://www.stackoverflow.com").getcode())
>>> 200
这篇关于通过Python检查网站是否已启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文