Checking if a website is up via Python

后端 未结 14 2070
南笙
南笙 2020-12-04 09:27

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 ?

14条回答
  •  难免孤独
    2020-12-04 10:17

    You may use requests library to find if website is up i.e. status code as 200

    import requests
    url = "https://www.google.com"
    page = requests.get(url)
    print (page.status_code) 
    
    >> 200
    

提交回复
热议问题