Python check if website exists

后端 未结 8 1946
甜味超标
甜味超标 2020-11-27 12:51

I wanted to check if a certain website exists, this is what I\'m doing:

user_agent = \'Mozilla/20.0.1 (compatible; MSIE 5.5; Windows NT)\'
headers = { \'User         


        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 13:21

    Try this one::

    import urllib2  
    website='https://www.allyourmusic.com'  
    try:  
        response = urllib2.urlopen(website)  
        if response.code==200:  
            print("site exists!")  
        else:  
            print("site doesn't exists!")  
    except urllib2.HTTPError, e:  
        print(e.code)  
    except urllib2.URLError, e:  
        print(e.args)  
    

提交回复
热议问题