Delete Google Browser History using Python

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 ‘www.geekforgeeks.org’, 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.

Implementation:

filter_none

edit
close

play_arrow

link
brightness_4
code

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
        print(rows)
          
        # we are first selecting the id
        id = rows[0]
          
        # append in ids which was initially
        # empty with the id of the selected url
        ids.append((id,))
           
    # 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
    conn.commit()
      
# close the connection 
conn.close()

chevron_right


Output:

(16886, 'https://www.geeksforgeeks.org/')



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.