我正在从一个简单的模板生成HTML页面:
add step
我如何创建标签的方法是使用一个简单的类生成一个简单的字符串:
--jars s3://emrb/hadoop_jars/emrfs-hadoop-assembly-2.32.0.jar,s3://emrb/gson-2.8.4.jar --driver-class-path s3://emrb/hadoop_jars/emrfs-hadoop-assembly-2.32.0.jar,s3://emrb/gson-2.8.4.jar --class org.springframework.boot.loader.JarLauncher
<div id="dateReference">
<h1 id="currentDate">Exploit automation completed on: {date_of_attack}</h1>
</div>
<div id="amountOfHost">
<h4 id="hostCount">Total of {amount_of_hosts} separate hosts attacked</h4>
</div>
<div id="hostDropDown" class="dropdown-content">
{all_hosts_attacked}
</div>
<div id="successfulAttacks">
<h4 id="successAttacksBanner">Successful Attacks:</h4>
</div>
{exploit_table}
函数正常运行,并且已成功生成,问题是当我尝试生成import os
import datetime
import lib.settings
class HtmlPageGenerator(object):
def __init__(self, successes, failures, host_count):
self.success = successes
self.fails = failures
self.host_count = host_count
self.html_template = lib.settings.HTML_PAGE_TEMPLATE
self.attacked_hosts_list = open(lib.settings.HOST_FILE).readlines()
def _generate_html_table(self, headers):
retval = '<table id="generatedExploitTable"><tr>'
for header in headers:
retval += "<th>{}</th>".format(header)
retval += "</tr><tr>"
for value in self.success:
retval += "<td>{}</td>".format(value)
retval += "</tr></table>"
return retval
def _generate_drop_down_menu(self):
retval = ""
for host in self.attacked_hosts_list:
retval += '<a href="#">{}</a>'.format(host.strip())
return retval
def generator(self):
if not os.path.exists(lib.settings.HTML_PAGE_PATH):
os.makedirs(lib.settings.HTML_PAGE_PATH)
with open(self.html_template, 'r') as template, open(lib.settings.HTML_PAGE_GENERATION_FILE_PATH, 'a+') as out:
to_format = template.read()
out.write(
to_format.format(
date_of_attack=str(datetime.datetime.today()).split(".")[0],
exploit_table=self._generate_html_table(["Exploit Paths"]),
amount_of_hosts=self.host_count,
all_hosts_attacked=self._generate_drop_down_menu()
)
)
return lib.settings.HTML_PAGE_GENERATION_FILE_PATH
标签时,它引发以下错误:
_generate_html_table
是什么导致我的错误,如何成功解决?我试图将链接生成为<a href="#"
,并返回连接,但它抛出相同的Traceback (most recent call last):
File "xxxxx.py", line 10, in <module>
23
File "/Users/admin/bin/tools/xxxxx/lib/page_generator.py", line 42, in generator
all_hosts_attacked=self._generate_drop_down_menu()
KeyError: '\n document'
。任何帮助都会很棒
答案 0 :(得分:0)
弄清楚了,我在HTML中使用了javascript,因此众所周知,javascript使用括号{}
来解析它们:{{}}
已修复。