我如何用SQLITE3PYTHON改变Chrome历史?

gudnpqoy  于 2022-11-15  发布在  SQLite
关注(0)|答案(1)|浏览(128)

这是我的代码

import sqlite3
conn = sqlite3.connect("path to chrome history")
c = conn.cursor()
c.executemany("UPDATE urls SET url = REPLACE(url,.foo.,.foo-bar.) WHERE url LIKE %foo%;")
conn.close()

它会抛出以下错误:

c.executemany("UPDATE urls SET url = REPLACE(url,.foo.,.foo-bar.) WHERE url LIKE %foo%;")
TypeError: executemany expected 2 arguments, got 1

如何在Python中使用Sqlite3更改Google Chrome中的历史记录?

jv2fixgn

jv2fixgn1#

午餐后我有一些时间来看这个,这就是我蹒跚在一起的东西。使用风险自负(在运行此命令之前备份“历史”文件)。

import sqlite3
 
conn = sqlite3.connect(r"path to chrome history")

c = conn.cursor()

for url in c.execute("SELECT * FROM urls WHERE url LIKE '%foo%'"):
    # Execute returns a tuple. Need to convert to list to edit.
    # Then convert back to tuple for use in f-string
    url = list(url)
    url[1] = url[1].replace("foo", "foo-bar") # String replace
    url = tuple(url)
    c.execute(f"REPLACE INTO urls VALUES {url}")

c.close()
conn.commit()
conn.close()

注意:Chrome必须关闭才能运行,否则文件将被锁定。

相关问题