Get Chrome tab URL in Python

后端 未结 3 1128
谎友^
谎友^ 2020-11-27 08:40

I want to get information about my Chrome tabs like the URL of the current tab or get all URLs automatically but I can\'t find any documentation about it. I installed the Ch

3条回答
  •  心在旅途
    2020-11-27 09:06

    You can get the current URL (or at least what is typed in the address bar) via

    from pywinauto import Application
    app = Application(backend='uia')
    app.connect(title_re=".*Chrome.*")
    element_name="Address and search bar"
    dlg = app.top_window()
    url = dlg.child_window(title=element_name, control_type="Edit").get_value()
    print(url)
    

    If you use another language the element_name might be different. You can get the corresponding name via inspect.exe which is part of the Windows 10 SDK\Windows Kit under C:\Program Files (x86)\Windows Kits\10\bin\x64\inspect.exe. Then just hover over the address bar and you'll find your name.

    This by the way works with many browsers:

    • Vivaldi: Search or enter an address
    • Firefox: Search with Google or enter address
    • Opera: Address field
    • Chrome: Address and search bar

提交回复
热议问题