I need to get all urls from all open Google Chrome tabs using python 3 without intefering with the user. My operating system is Windows 10 and I use Microsoft Visual Studio Python3.
I have tried the following things:
Opening the tabs directly using open(path_to_current_tabs). This doesn't work because I don't have permission to read the file. I think that it's locked because chrome is actively writing to it.
Current_Tabs_Source = open(r"C:\Users\Beni\AppData\Local\Google\Chrome\User Data\Default\Current Tabs", "r")
Current_Tabs_Raw = Current_Tabs_Source.read()
print(Current_Tabs_Raw) #just for checking
The resulting error:
PermissionError: [Errno 13] Permission denied
Opening using the history SQlite3 database also doesn't work because it's locked. But I can't find a password anywhere. I have also tried to open the History for the urls, but that didn't work either.
import sqlite3
from os import path
data_path = path.expanduser('~') + r"\AppData\Local\Google\Chrome\User
Data\Default"
files = listdir(data_path)
history_db = path.join(data_path, 'history')
c = sqlite3.connect(history_db)
cursor = c.cursor()
select_statement = "SELECT urls.url, urls.visit_count FROM urls, visits
WHERE urls.id = visits.url;"
cursor.execute(select_statement)
results = cursor.fetchall()
print(results) #just for checking
This results in the following error:
sqlite3.OperationalError: database is locked
Using selenium and a third party chrome extension to copy all urls to the clipboard didn't work either, because these extensions only work in the active selenium window. So the links of the tabs that I want don't get copied.
I have considered hacking together a chrome extension that copies the urls every 30 sec to a temp file, but my javascript knowledge is minimal, so that thing is driving me mad.
Does anyone know a way to do this in Python? Any other solution would be greatly appreciated.