2

I am trying to get the url of active tabs of Google Chrome and other browsers.

I have tried to open the session files of Mozilla Firefox but the output of the code is getting wrong.

import json
f = open(r"C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ad0v8pf6.defaul
t\sessionstore.js", "r")
jdata = json.loads(f.read())
f.close()
print(str(jdata["windows"][0]["selected"]))
for win in jdata.get("windows"):
          for tab in win.get("tabs"):
                  i = tab.get("index") - 1
                  print(tab.get("entries")[i].get("url"))

The code returns number of current tabs that are open and their url, but I am getting output as 2 and two urls, but 5 tabs were open at that time.

I have also tried selenium but no progress.

bastelflp
  • 9,362
  • 7
  • 32
  • 67
Abhishek Suran
  • 169
  • 3
  • 10
  • 2
    What's the contents of `sessionstore.js`? Does it contain what you need? See how to create a [mcve]. – Peter Wood Nov 11 '17 at 13:04
  • sir , it contains the information about the current tabs and their url – Abhishek Suran Nov 11 '17 at 13:12
  • 1
    Have a look at https://stackoverflow.com/questions/11645123/how-do-i-get-the-url-of-the-active-google-chrome-tab-in-windows or https://stackoverflow.com/questions/7537832/list-of-open-browser-tabs-programmatically – bastelflp Nov 11 '17 at 17:29
  • sessionstore just save that website who wants to save their own sessions!! for other website will not work! i recommend you to read about "what is website session" ... – DRPK Nov 11 '17 at 18:07
  • Check out https://github.com/balta2ar/brotab – Kris Dec 13 '20 at 09:33

0 Answers0