Python check if website exists
问题 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-Agent\':user_agent } link = \"http://www.abc.com\" req = urllib2.Request(link, headers = headers) page = urllib2.urlopen(req).read() - ERROR 402 generated here! If the page doesn\'t exist (error 402, or whatever other errors), what can I do in the page = ... line to make sure that the page I\'m reading does exit? 回答1: You can use HEAD