#!/usr/bin/python
-
-Coding:utf-8--
#Author = = Huangyishan
Import OS
Import Sys
Import Urllib2
URLs = sys.argv[1] #从程序外部调用参数, 0 is the program itself
result = List ()
Def check_url_status ():
f = open (URLs, ' R ') #以读方式打开文件
For line in F.readlines (): #依次读取每行
line = Line.strip () #去掉每行头尾空白
If Len (line)!=0:
If line[0:7]== '//' or line[0:8]== ' https://':
Pass
Else
Line= ' http//' +line
Print Line
Try
#response = Urllib2.urlopen (line,timeout=4)
Status = Urllib2.urlopen (line,timeout=4). Code
#print response
Print status
Result.append (line)
Open (' Url_ok.txt ', ' W '). Write ('%s '% ' \ n '. Join (Result)) #保存入结果文件
Except Urllib2. Httperror, E:
Print E.code
With open (' Url_notok.txt ', ' W ') as F: #保存入结果文件
F.write (line + ': ' + str (e.code) + ' \ n ')
Except
Print "Error"
With open (' Url_notok.txt ', ' a ') as F: #保存入结果文件
F.write (line + ': ' + ' error ' + ' \ n ')
If name = = 'main':
Check_url_status ()
Python detects the bulk URL status and returns a normal URL to save the file