python脚本执行错误

python脚本执行错误
我要执行这个脚本

img


执行结果是这样的按任意键就闪退

img


代码下面有

代码呢

你至少让大家看下一的脚本啊,这样看不出来

#!/usr/bin/env python3

-- coding:utf8 --

#"""
#author = 'WSK' # first version, extract vul from index.html
#author = 'CL' # extract port from detail html ,change export file format to real excel;
#绿盟极光扫描器V6专用
#"""

from bs4 import BeautifulSoup
import re
import os
from openpyxl import Workbook
import sys

def getrisk(level):
if level == 'level_danger_high':
risk = '高'
elif level == 'level_danger_middle':
risk = '中'
elif level == 'level_danger_low':
risk = '低'
else:
risk = '无'

return risk

def gettype(vulname):
#"""
#:param vulname: 漏洞名称字符串
#:return: 设备类型
#"""
# 中间件(tomcat等)
vul = vulname.lower()
isapache = re.compile('apache')
isphp = re.compile('php')
isnginx = re.compile('nginx')
islighttpd = re.compile('lighttpd')
# 中间件(WAS)
iswas = re.compile('.webshpere.')
isibm = re.compile('ibm')
# 数据库
ismyql = re.compile('.mysql.')
isoracle = re.compile('oracle')
isredis = re.compile('redis')
# match
apache = isapache.match(vul)
php = isphp.match(vul)
nginx = isnginx.match(vul)
lighttpd = islighttpd.match(vul)
was = iswas.match(vul)
ibm = isibm.match(vul)
mysql = ismyql.match(vul)
oracle = isoracle.match(vul)
redis = isredis.match(vul)

if apache or php or nginx or lighttpd:
    type = u'中间件(tomcat等)'
elif was or ibm:
    type = u'中间件(was)'
elif mysql or redis:
    type = u'数据库(mysql等)'
elif mysql is None and oracle:
    type = u'数据库(oracle)'
else:
    type = u'主机'

return type

def genfilelist(path):
#"""
#:param path: 输入路径
#:return: 返回路径下所有html文件名组成的列表
#"""
filelist = os.listdir(path)
newlist = []
for names in filelist:
if names.endswith(".html"):
newlist.append(names)
return newlist

def extract_index(index):
brackets = re.compile('(.*)')
index_string = brackets.findall(index)
t = index_string[0]
table_node = t.strip('()').split(',')[1].strip("'")
return table_node

def extract_detail(soup, index):
vul_info = {}
vul_info_table = soup.find('tr', id=index)
vul_info_list = vul_info_table.find('tr')
vuldesc = vul_info_list.find('td').get_text(strip='\t')
vuladvice = vul_info_list.next_sibling.next_sibling.find('td').get_text(strip='\t')
vul_info['desc'] = vuldesc
vul_info['advice'] = vuladvice
links = vul_info_table.find_all('a')
vul_cve = '无'
cve_pattern = re.compile('CVE-.*')
for link in links:
if cve_pattern.match(link.get_text()):
vul_cve = link.get_text()
else:
pass

vul_info['cve'] = vul_cve
return vul_info

def extract_info(path):
#"""
#:return: all vul info with port
#"""
xls = u'漏洞汇总.xlsx'
xlswb = Workbook()
xlswb.save(filename=xls)
xlsws = xlswb.active
xlsws.append(['IP', u'设备类型', u'风险等级', u'CVE编号', u'漏洞名称', u'漏洞描述', u'整改意见', u'端口'])

volume = path + 'host/'
filelist = genfilelist(volume)
for filename in filelist:
    file = volume + filename
    try:
        html = open(file, 'rb')
    except:
        continue

    soup = BeautifulSoup(html, 'lxml', from_encoding="utf8")
    ip_node = soup.select('div#content div.report_content table tr td table.report_table.plumb tbody tr.even td')
    ip = ip_node[0].get_text()

    vul_node = soup.select('div.vul_summary')
    for node in vul_node:
        attr = node.attrs
        port = attr["data-port"]
        vulname_node = node.find('span')
        level = vulname_node['class'][0]
        vul_info_index = vulname_node['onclick']
        vulname = vulname_node.get_text()
        vul_index = extract_index(vul_info_index)
        allvul = extract_detail(soup, index=vul_index)
        vultype = gettype(vulname)
        vulrisk = getrisk(level)
        if vulname == "Portable OpenSSH 'ssh-keysign'本地未授权访问漏洞":
            vulcve = 'CVE-2011-4327'
        elif vulname == "Portable OpenSSH 'ssh-keysign'本地未授权访问漏洞":
            vulcve = 'CVE-2011-4327'
        else:
            vulcve = allvul['cve']
        print(ip, vulname)
        list = [ip, vultype, vulrisk, vulcve, vulname, allvul['desc'], allvul['advice'], port]
        if vulrisk == '低':
            pass
        else:
            xlsws.append(list)

xlswb.save(filename=xls)
xlswb.close()

if name == 'main':
path = sys.argv[1]
extract_info(path)

if __name__ == "__main__":
    path = sys.argv[1]
    extract_info(path)

前面主体代码没看,最后的一看就有点小问题