Skip to content
Related Articles

Related Articles

Improve Article

Delete Google Browser History using Python

  • Last Updated : 16 Jul, 2020

In this article, you will learn to write a Python program which will take input from the user as a keyword like Facebook, amazon, geeksforgeeks, Flipkart, youtube, etc. and then search your google chrome browser history for that keyword and if the keyword is found in any of the URL then it will delete it. For example, suppose you have entered the keyword ‘geeksforgeeks’, so it will search your google chrome history, like ‘’, it’s very obvious that this URL contains the keyword ‘geeksforgeeks’, then it will delete it, it will also search for articles (like “Is geeksforgeeks a good portal to prepare for competitive programming interview?”) containing ‘geeksforgeeks’ in their title and delete it. First of all, get the location in your system where the google chrome history file is located.

Note: Google chrome history file location in windows generally is: C:\Users\manishkc\AppData\Local\Google\Chrome\User Data\Default\History.


import sqlite3
# establish the connection with
# history database file which is 
# located at given location
# you can search in your system 
# for that location and provide 
# the path here
conn = sqlite3.connect("/path/to/History")
# point out at the cursor
c = conn.cursor()
# create a variable id 
# and assign 0 initially
id = 0  
# create a variable result 
# initially as True, it will
# be used to run while loop
result = True
# create a while loop and put
# result as our condition
while result:
    result = False
    # a list which is empty at first,
    # this is where all the urls will
    # be stored
    ids = []
    # we will go through our database and 
    # search for the given keyword
    for rows in c.execute("SELECT id,url FROM urls\
    WHERE url LIKE '%geeksforgeeks%'"):
        # this is just to check all
        # the urls that are being deleted
        # we are first selecting the id
        id = rows[0]
        # append in ids which was initially
        # empty with the id of the selected url
    # execute many command which is delete
    # from urls (this is the table)
    # where id is ids (list having all the urls)
    c.executemany('DELETE from urls WHERE id = ?',ids)
    # commit the changes
# close the connection 


(16886, '')

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :