【发布时间】:2019-08-09 20:36:40
【问题描述】:
我需要将书签批量导入不同的网络浏览器。书签最初将存储在 CSV 文件中,在处理后,它们应该变成可以上传到任何 Web 浏览器的 HTML 文件。 我的解决方案需要与平台无关。
一个示例csv文件如下:
friendly,url,folder
CUCM - North,cucm-n.acme.com,ACME/CUCM/North
CUCM - PUB,cucm-pub.acme.com,ACME/CUCM
UCCX - South,uccx-south.acme.com,ACME/UCCX/South
UCCX - North,uccx-north.acme.com,ACME/UCCX/North
UCCX - PUB,uccx-pub.acme.com,ACME/UCCX
Database,db.acme.com,ACME
CUCM - North2,cucm-n2.acme.com,ACME/CUCM/North
生成的 HTML 文件如下所示:
HTML
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3 PERSONAL_TOOLBAR_FOLDER="true">Bookmarks bar</H3>
<DL><p>
<DT><H3>ACME</H3>
<DL><p>
<DT><H3>CUCM</H3>
<DL><p>
<DT><H3>North</H3>
<DL><p>
<DT><A HREF="http://cucm-n.acme.com/">CUCM - North</A>
<DT><A HREF="http://cucm-n2.acme.com/">CUCM - North2</A>
</DL><p>
<DT><A HREF="http://cucm-pub.acme.com/">CUCM - PUB</A>
</DL><p>
<DT><H3>UCCX</H3>
<DL><p>
<DT><H3>South</H3>
<DL><p>
<DT><A HREF="http://uccx-south.acme/">UCCX - South</A>
</DL><p>
<DT><H3>North</H3>
<DL><p>
<DT><A HREF="http://uccx-north.acme/">UCCX - North</A>
</DL><p>
<DT><A HREF="http://uccx-pub.acme.com/">UCCX - PUB</A>
</DL><p>
<DT><A HREF="http://db.acme.com/">Database</A>
</DL><p>
</DL><p>
</DL><p>
到目前为止,我的脚本如下:
import csv
bookmarks_spreadsheet = filedialog.askopenfilename()
reader = csv.DictReader(open(bookmarks_spreadsheet, 'r', encoding="utf-8-sig"))
for row in reader:
bookmarks.append(row)
url = row['url']
friendly = row['friendly']
folder = row['folder']
请帮助生成我预期的 HTML 文件所需的剩余代码。
【问题讨论】:
-
StackOverflow 不是代码编写服务。
标签: html python-3.x csv