本文介绍了通过 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 ?
干杯
推荐答案
您可以尝试使用
You could try to do this with getcode()
from urllib
import urllib.request
print(urllib.request.urlopen("https://www.stackoverflow.com").getcode())
200
对于 Python 2,使用
For Python 2, use
print urllib.urlopen("http://www.stackoverflow.com").getcode()
200
这篇关于通过 Python 检查网站是否已启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!