Home > Mobile >  How can i change chrome history with sqlite3 python?
How can i change chrome history with sqlite3 python?

Time:10-06

This is my code

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()

It throws the following error:

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

How can I change the history in Google Chrome using sqlite3 in Python?

CodePudding user response:

I had some time to look at this after lunch and this is what I hobbled together. Use at your own risk (make a backup of the "History" file before running this).

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()

Note: Chrome has to be closed for this to run else the file will be locked.

  • Related