2

I want to analyze the chrome activity which sites are open in current tab even if it open into the next tab also using python 3 . Please can anyone provide link or any suggestion how can i get that . I want to get that into python console. for ex. If i open new url it should be print into console

Thank you in advance.

I already tried and I get it from the Chrome history but for that I need to close browser but I actually want to trace which url is one and while running code which url newly open It should also update into console.

Rin
  • 81
  • 1
  • 2
  • 11
  • So this question may need more refinement on your end. Have you taken a look at `selenium` and their `ChromeDriver`? You most likely can view open tabs and build a function that prints to console. – ParalysisByAnalysis Sep 12 '19 at 05:39
  • From that I can open url but I want app like chrome history when i open new url it should instantly update into console can we do it also using selenium ? – Rin Sep 12 '19 at 05:52
  • I am not a Chrome user, but I found this link that might be helpful -https://geekswipe.net/technology/computing/analyze-chromes-browsing-history-with-python/ – Sid Sep 12 '19 at 05:54
  • Thankyou for answer @Sid Yes I can find it from https://geekswipe.net/technology/computing/analyze-chromes-browsing-history-with-python/ but it should be restricted to you have to close chrome and I want runtime output . – Rin Sep 12 '19 at 05:59
  • For that I need to close Chrome after that only I get URL but I want to do It without closing Chrome @Sid – Rin Sep 12 '19 at 06:05
  • Which OS? I don't think it's possible in Windows, however, in MacOs, this question might be helpful. https://stackoverflow.com/questions/7537832/list-of-open-browser-tabs-programmatically – Sid Sep 12 '19 at 06:11
  • I used windows 7 and python 3.x – Rin Sep 12 '19 at 06:13
  • Does this answer your question? [Get Chrome tab URL in Python](https://stackoverflow.com/questions/52675506/get-chrome-tab-url-in-python) – skjerns Jan 26 '20 at 14:02

1 Answers1

4

I have face same problem with accessing Chrome's address bar, but found a way to do it with pywinauto library. See code below.

from pywinauto import Application
app = Application(backend='uia')
app.connect(title_re=".*Chrome.*")
dlg = app.top_window()
url = dlg.child_window(title="Adreso ir paieškos juosta", control_type="Edit").get_value()
print(url)

"Adreso ir paieškos juosta" is element name of Chrome address bar as I am using Chrome with Lithuanian language, it is in Lithuanian. If you want to find element's name use inspect.exe, it will show the name. You can find more info about inspect.exe in pywinauto documentation page or just google it.

Hope this will help you.

  • 1
    For English it would be "Address and search bar". For your own language you can use inspect.exe (microsoft tool kit) and hover above the address bar. – skjerns Jan 13 '20 at 08:32
  • This method seems not work for me now. Here is the code I use I am Chinese I checked the control name by inspect.exe already, even I change the ;default language of chrome to english, get the same error. I get the error like > AttributeError: WindowSpecification class has no 'get_value' method How to debug and solve this problem? – Lee Jul 15 '20 at 07:57
  • You can refer to my implementation that does not restrict locale and browser and more faster. @Lee https://stackoverflow.com/a/63703030/11687405 – bruce Sep 02 '20 at 10:01