首先贴上简陋的python脚本
#coding:utf-8 import urllib,linecache for line in linecache.updatecache('url.txt'): try: code = urllib.urlopen(line.strip('\n')).getcode() print code except Exception,e: print e if code == 200: with open('url_new.txt','a') as fw: fw.write(line)
简述自己踩的一个坑:
有些地方用空格代替制表符,导致程序运行出错,报错信息:unindent does not match any outer indentation level
我用的notepad++,依次选择“视图”-“显示符号”-“显示空格与制表符”
发现if语句前用了空格,将其改为制表符后,程序就可以正常运行了。