2015-06-11 27 views
1

我真的被陷在我试图做的事情。 我想打一个非常简单的脚本,以显示谷歌浏览器的历史记录。 当我使用下面的代码行:蟒蛇3.4谷歌浏览器的历史

f = open('C:\\Users\\joey\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History', 'rb') 
data = f.read() 
f.close() 

我得到一个输出,我只西港岛线显示部分,因为它西港岛线太长,否则。

x00\x00\x00\x00\x00\x81#\x9cU\n\x00\x81yC\t\x08\x06\x08\x08https://www.google.nl/search?q=de+zigodoom&oq=de+zigodoom&aqs=chrome..69i57.1507j0j7&sourceid=chrome&es_sm=93&ie=UTF-8de zigodoom 

如何显示网站而不是所有的x00/x000输出。我怎样才能在不同的行上显示每个网站。

for d in data: 
print(data) 

Wil这样容易的循环工作?

+0

在文件顶部显示[SQLite](https://docs.python.org/2/library/sqlite3.html)格式。 –

+0

可能重复:http://stackoverflow.com/questions/4643142/regex-to-test-if-string-begins-with-http-or-https – sgp

+0

长话短说,历史文件是** **不只是一个平面文本的网站列表。此外,您的'for'循环是没有意义的 - 这是不正确的缩进你为什么要打印你遍历对象* *以上的循环中? – jonrsharpe

回答

2

谷歌Chrome浏览器的历史记录存储在一个数据库SQLite。自从Python 2.5以来,Python已经通过sqlite3支持这种开箱即用的方式。

import sqlite3 
con = sqlite3.connect('C:\\Users\\joey\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History') 
cursor = con.cursor() 
cursor.execute("SELECT url FROM urls") 
urls = cursor.fetchall() 
print('\n'.join(urls)) 
+1

你好!非常感谢您的帮助。 我得到下一个错误:sqlite3.OperationalError:数据库被锁定 – joey

+0

这是因为Chrome正在使用它。 –

+0

关闭Chrome,仍然给我同样的错误 –