Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Getting all Urls from every open Google Chrome Tab

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 = Current_Tabs_Source.read()
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 
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

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.

like image 764
Beni G Avatar asked Dec 27 '17 17:12

Beni G


People also ask

How do I copy the URL address of all open tabs in Chrome?

Click Use Current Pages below the box to load all the URLs from all the tabs into the box. Then, put the cursor in the box, select all (Ctrl + A), and copy (Ctrl + C).

Is there a way to do text search across all open tabs Chrome?

Using the keyboard shortcut Cmd + Shift + A (Mac) or Ctrl + Shift + A (Windows), you can pull up a sidebar of your recent Chrome tabs and search all of them at once.


1 Answers

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

(Source)

like image 93
Dedenne_Cute Avatar answered Sep 26 '22 16:09

Dedenne_Cute