3.6.2python
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)
app
2.6ui
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
import urllib2
import timeurl
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) utf-8
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)
test