import os
import webbrowser
path = "D:\\文档&文件" # 文件夹路径
GEN_HTML = "test.html"
f = open(GEN_HTML, 'w')
names = os.listdir(path)
str1 = []
tag = "<p></p>"
for i in names:
tag += "<p>    "+str(i)+"</p>\n"
print(tag)
message = """
<html>
<head></head>
<body>
"""+str(tag)+"""
</body>
</html>
""" #% (str1)
f.write(message)
# 关闭文件
f.close()
# 运行完自动在网页中显示
webbrowser.open(GEN_HTML, new=1)