python 将Firefox sessionstore.js文件转换为html。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 将Firefox sessionstore.js文件转换为html。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python

################################################################################
# usage: session2html.py [-h] -s SESSION_FILE [-o OUTPUT_FILE]
#
# Convert Firefox sessionstore.js file to html.
#
# optional arguments:
#   -h, --help       show this help message and exit
#   -s SESSION_FILE  session file to be converted
#   -o OUTPUT_FILE   write html output to OUTPUT_FILE; if not defined write html
#                    output to stdout
################################################################################


import os, sys, json, time, argparse
from xml.sax.saxutils import escape

html_escape_table = {
    '"': """,
    "'": "'"
}

# escapes this characters: '&', '<', '>', '"', and ''' 
def html_escape(text):
    return escape(text, html_escape_table)

# parse script arguments
desc="Convert Firefox sessionstore.js file to html."
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("-s", dest="sessionfile", type=argparse.FileType('r'), 
      metavar="SESSION_FILE", required=True, help="session file to be converted")
parser.add_argument("-o", dest="outputfile", type=argparse.FileType('w'),
      default=sys.stdout, metavar="OUTPUT_FILE", help="write html output \
      to OUTPUT_FILE; if not defined write html output to stdout")    
args = parser.parse_args()

# read session file and parse it to json structure
ss = json.loads(args.sessionfile.read().decode("utf-8"))


mtimeInfo = "<p>File mtime {0}</p>".format(
      time.ctime(os.stat(args.sessionfile.name).st_mtime))

lastUpdateInfo = ""
if "session" in ss:
    if "lastUpdate" in ss["session"]:
        lastUpdateInfo = "<p>Recorded session.lastUpdate {0}</p>".format(
              time.ctime(ss["session"]["lastUpdate"]/1000.0))



args.outputfile.write("""
<html>
<head>
 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
 <title>Open Tabs from session file</title>
</head>
<body>
<h1>Open Tabs from Session File</h1>
{0}
{1}
<ul style="list-style-type:none">
""".format(mtimeInfo, lastUpdateInfo))

counter = 1
for window in ss["windows"]:
    for tab in window["tabs"]:
        entries = tab["entries"]
        args.outputfile.write('<li>#{0}<ul style="list-style-type:none">'.format(
              counter))
        for entry in entries:
            url = entry["url"].encode("utf-8")
            title = html_escape(entry.get("title", url)).encode("utf-8")
            line = '<li><a href="{0}">{1}</a> : <tt>{2}</tt></li>\n'.format(
                  url, title, url)
            args.outputfile.write(line)
        args.outputfile.write("</ul>")
        print "tabs processed: {0}".format(counter)
        counter += 1
args.outputfile.write("""
</ul>
<p></p>
</body>
</html>
"""
)
args.outputfile.close()

以上是关于python 将Firefox sessionstore.js文件转换为html。的主要内容,如果未能解决你的问题,请参考以下文章

ASP.NET中Session的sessionState 4种mode模式

ModuleNotFoundError:没有名为“utils.SessionState”的模块

表单身份验证超时与 sessionState 超时

SessionState的几种设置

在C#中,在Web.Config文件中加入<sessionState mode="InProc"></sessionState>语句

SessionState stateConnectionString 和 sqlConnectionString