3.6.2
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.baidu.com/','http://www.baidu.com'] # 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)
2.6
#!/usr/bin/python2.6 # -*- coding: utf-8 -*- import urllib2 import time
opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/49.0.2')] #这个是你放网址的文件名,改过来就可以了 # file = open('test.txt') # lines = file.readlines() aa=['http://www.baidu.com.com/','http://www.baidu.com'] # 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({});