简体   繁体   中英

How can i change chrome history with sqlite3 python?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM