相关疑难解决方法(0)

Python检查网站是否存在

我想检查某个网站是否存在,这就是我正在做的事情:

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!
Run Code Online (Sandbox Code Playgroud)

如果页面不存在(错误402,或其他任何错误),我该怎么做page = ...才能确保我正在阅读的页面退出?

html python urlopen

50
推荐指数
7
解决办法
9万
查看次数

标签 统计

html ×1

python ×1

urlopen ×1