Checking if a website is up via Python

后端 未结 14 2039
南笙
南笙 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:20

    my 2 cents

    def getResponseCode(url):
    conn = urllib.request.urlopen(url)
    return conn.getcode()
    
    if getResponseCode(url) != 200:
        print('Wrong URL')
    else:
        print('Good URL')
    

提交回复
热议问题