Python能访问Google Chrome的WebSQL数据库吗
我有一个本地的网页客户端,它使用webSQL在客户端存储数据。(是的,我知道这个技术已经被淘汰了)。
我还有一个Python脚本,用来生成报告,并且现在通过一个驱动程序从mdb文件中获取数据。
我在想,是否可以通过Python从谷歌浏览器的webSQL数据库中获取我的数据。
我不太确定如何在Python脚本中调用谷歌浏览器中的数据库文件,或者这是否可能。
任何帮助都将非常感激。
2 个回答
0
我希望我理解了你的问题:在Chrome的用户数据文件夹里(在Windows上是这么叫的),有趣的文件通常是JSON文件或者SQLite数据库文件。你可以用Python标准库里的sqlite3模块来访问后者。不过,那里有个自述文件上写着:
Google Chrome settings and storage represent user-selected preferences and
information and MUST not be extracted, overwritten or modified except through
Google Chrome defined APIs.
2
好的,我的同事找到了办法。
在Windows系统上,你可以去:
C:\Users\<UserName>\AppData\Local\Google\Chrome\User Data\Default\databases
这里有很多不同网站用sqlite存储的数据库。
然后,Python脚本就简单得多了:
import sqlite3
conn = sqlite3.connect(<dbFile>)
cursor = conn.cursor()
print "\nHere's a listing of all the records in the table:\n"
for row in cursor.execute("SELECT * FROM <TableName>"):
print row