[Python] 纯文本查看 复制代码import urllib.request
#添加请求头
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE')]
#获取检测网址到列表,当前目录下 urls.txt 文件,每个检测网址占一行
file = open(r'urls.txt')
lines = file.readlines()
wwws = []
for line in lines:
temp = line.replace('\n', '')
wwws.append(temp)
#print(wwws)
#检测并输出检测结果
for www in wwws:
tempUrl = www
try:
opener.open(tempUrl)
print(tempUrl + '正常访问')
except urllib.error.HTTPError:
print(tempUrl + '=访问页面出错,HTTPError')
except urllib.error.URLError:
print(tempUrl + '=访问页面出错,URLError')
运行效果:
2023-02-28_162632.jpg (39.05 KB, 下载次数: 0)
下载附件
2023-2-28 16:26 上传