import urllib.request import time opener = urllib.request.build_opener() opener.addheaders = [('User-agent', 'Mozilla/49.0.2')] #这个是你放网址的文件名,改过来就可以了 # file = open('test.txt') # lines = file.readlines() aa=['http://www.jd.com/','https://top.jd.com/?cateId=794&itemId=6254701'] # for line in lines: # temp=line.replace('\n','') # aa.append(temp) # print(aa) print('开始检查:') for a in aa: tempUrl = a try : opener.open(tempUrl) print(tempUrl+'没问题') except urllib.error.HTTPError: print(tempUrl+'=访问页面出错') time.sleep(2) except urllib.error.URLError: print(tempUrl+'=访问页面出错') time.sleep(2) time.sleep(0.1)
(adsbygoogle = window.adsbygoogle || []).push({});
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有