Python check if website exists

后端 未结 8 1855
甜味超标
甜味超标 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:15

    def isok(mypath):
        try:
            thepage = urllib.request.urlopen(mypath)
        except HTTPError as e:
            return 0
        except URLError as e:
            return 0
        else:
            return 1
    

提交回复
热议问题