Python: Getting all Urls from every open Google Chrome Tab

python python-3.x google-chrome selenium sqlite

1403 观看


51 作者的声誉

I need to get all the urls from all open Google Chrome tabs in python 3 without intefering with the user. Im on Windows 10 using Microsoft Visual Studio Python3

Ive tried:

Opening it directly with open(path to current tabs)-- doesnt work because i have no permission- i think its locked because chrome activly writes to it.

Current_Tabs_Source = open(r"C:\Users\Beni\AppData\Local\Google\Chrome\User 
Data\Default\Current Tabs", "r")
Current_Tabs_Raw =
print(Current_Tabs_Raw) #just for checking 

PermissionError: [Errno 13] Permission denied

Opening through sglite3 -- doesnt work because its locked. And i cant find a password anywhere. Ive tried to open the History for the urls but it doesnt work anyways.

import sqlite3
from os import path

data_path = path.expanduser('~') + r"\AppData\Local\Google\Chrome\User 
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 = visits.url;"

results = cursor.fetchall()

print(results) #just for checking

sqlite3.OperationalError: database is locked

Using selenium and a 3rd party chrome extension to copy all urls to the clipboard -- doesnt work because these extensions only work in the active selenium window. So the Windows with the tabs in it that i want dont get copied.

Ive considered hacking together a chrome extension that copys the urls every 30 sec to a temp file. But i only know minimal Javascript so this thing is driving me mad.

So does anyone know a way to do this in Python ? Any other solution is greatly appreciated.

作者: Beni G 的来源 发布者: 2017 年 12 月 27 日

回应 1


52 作者的声誉

If you want to access the database, you should close all browsers.


作者: HERO 发布者: 2018 年 3 月 8 日