我是Python脚本的新手。我创建了一个HTML页面,顶部有5个标题,页面底部有5个表格。如果我点击heading-1,它必须转到表1,反之亦然。
我使用HTML.table()
函数创建表,使用HTML.link()
创建超链接。但是如何解决我无法找到的表格的特定位置。请建议我更好的方法,如何做到这一点。
- 代码 -
#!/usr/bin/python
import openpyxl
import os
from openpyxl import load_workbook
import HTML
def create_link(data,link, file_name):
html_fil = open(file_name, "a")
htmlcode_3 = HTML.link(data,link)
html_fil.write(htmlcode_3)
html_fil.close()
def del_html_file(html_file):
if os.path.exists(html_file):
os.remove(html_file)
# Main exe starts from here
html_data_1 = ["AAA"]
html_data_2 = ["BBB"]
html_data_3 = ["CCC"]
del_html_file("sample.html")
print('---EXECUTION Started---')
html_fil = open("sample.html", "a")
create_link('TABLE1', 'sample.html#TABLE1','sample.html')
create_link('TABLE2', 'sample.html#TABLE2','sample.html')
create_link('TABLE3', 'sample.html#TABLE3','sample.html')
create_link('TABLE4', 'sample.html#TABLE4','sample.html')
create_link('TABLE5', 'sample.html#TABLE5','sample.html')
A = HTML.Table(header_row=['Table - A'])
A.rows.append([html_data_1, html_data_2,html_data_3])
B = HTML.Table(header_row=['Table - B'])
B.rows.append([html_data_1, html_data_2,html_data_3])
C = HTML.Table(header_row=['Table1 -C'])
C.rows.append([html_data_1, html_data_2,html_data_3])
D = HTML.Table(header_row=['Table - D'])
D.rows.append([html_data_1, html_data_2,html_data_3])
E = HTML.Table(header_row=['Table1 - E'])
E.rows.append([html_data_1, html_data_2,html_data_3])
htmlcode_1 = str(A)
htmlcode_2 = str(B)
htmlcode_3 = str(C)
htmlcode_4 = str(D)
htmlcode_5 = str(E)
with open("sample.html", "a") as html_fil:
html_fil.write(htmlcode_1)
html_fil.write("<br />")
html_fil.write(htmlcode_2)
html_fil.write("<br />")
html_fil.write(htmlcode_3)
html_fil.write("<br />")
html_fil.write(htmlcode_4)
html_fil.write("<br />")
html_fil.write(htmlcode_5)
html_fil.write("<br />")
print('---EXECUTION END---')