# -*- coding: utf-8 -*-
import urllib.request
import time
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/49.0.2')]
#文件格式http://www.baidu.com
file = open('E:/auto/url.txt')
lines = file.readlines()
aa=[]
for line in lines:
temp=line.replace('\n','')
aa.append(temp)
print(len(aa),"----------------------------","\n",aa)
print ("start check")
newfile = open("f:/URL_open.txt","a")
for a in aa:
try :
opener.open(a)
print(a+" isok")
newfile.write(a+"\n")
except urllib.error.HTTPError:
#print(a+'=访问页面出错')
print (a+"error")
time.sleep(2)
except urllib.error.URLError:
#print(a+'=访问页面出错')
print (a + "error")
time.sleep(2)
time.sleep(0.1)
newfile.close()