python脚本检查网页能否打开

批量判断网站能否访问,可以使用urllib的getcode()方法

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from urllib.request import urlopen

url = 'http://www.baidu.com'
resp = urlopen(url)
code = resp.getcode()
print('the result is :', code)

运行结果: 
这里写图片描述


参考: 
http://stackoverflow.com/questions/2792650/python3-error-import-error-no-module-name-urllib

                                                                    欢迎关注公众号,和我一起成长!

                                                         

猜你喜欢

转载自blog.csdn.net/qq_42914528/article/details/81634493