I need to traverse the directory in the process of doing the problem, I simply wrote the scan script, but I have not learned multi-threading, so let ’s do it first.
import urllib.request as req
import urllib.error as er,sys
file_hou=['.tar','.tat.gz','.zip','.rar','.bak']
file_name=['web','website','backup','back','www','wwwroot','temp']
f=open("D:/lenovo/desktop/ctfhub.txt",'a',encoding=('utf-8'))
web_success=[]
n=(len(file_name)*len(file_hou))
nn=0
for x in file_name:
for y in file_hou:
try:
url = 'http://taobao.com'+x+y
webpage = req.urlopen(url) # 根据超链访问链接的网页
#print(url + " ok")
web_success.append(url)
except er.HTTPError as e:
#print(url + " ", e)#显示错误信息
pass
except er.URLError as f:
#print(url + " ", f)#显示错误信息
pass
except:
#print(sys.exc_info())#显示错误信息
raise
nn+=1
print("%.2f"%((nn/n)*100),"%")#进度显示
for x in web_success:
f.write(x)
note:
- The HTTPError and URLError exception handling in urllib2 have been merged into urllib
- If you want to save the result to the text, open the text with encoding = ('utf-8'), txt defaults to gbk encoding, and pycharm also uses the system encoding by default.