http-head

Checking if a website is up via Python

冷暖自知 提交于 2019-11-27 09:31:32
问题 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 ? Cheers Related How do you send a HEAD HTTP request in Python? 回答1: You could try to do this with getcode() from urllib >>> print urllib.urlopen("http://www.stackoverflow.com").getcode() >>> 200 EDIT: For more modern python, i.e. python3 , use: import urllib.request print(urllib.request.urlopen("http://www.stackoverflow.com").getcode()) >>> 200