Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a website is up via Python

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?
like image 413
Hellnar Avatar asked Dec 22 '09 21:12

Hellnar


People also ask

How do you know if a website is reachable?

Visit Website Planet. Enter the URL of your website address on the field and press the Check button. Website Planet will show whether your website is online or not.

Can you use Python to interact with websites?

The technique of automating the web with Python works great for many tasks, both general and in my field of data science. For example, we could use selenium to automatically download new data files every day (assuming the website doesn't have an API).

Can Python open a website?

just open the python interpreter and type webbrowser. open('http://www.google.com') and see if it does what you want. yes. The result is same.


1 Answers

You could try to do this with getcode() from urllib

import urllib.request  print(urllib.request.urlopen("https://www.stackoverflow.com").getcode()) 
200 

For Python 2, use

print urllib.urlopen("http://www.stackoverflow.com").getcode() 
200 
like image 127
Anthony Forloney Avatar answered Nov 08 '22 11:11

Anthony Forloney