获取Python中的活动Chrome URL

2024-05-16 04:12:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用uiautomation的python包装器来获取chrome窗口的活动url。然而,这个脚本只得到某些网站(如youtube或google),而没有得到其他网站(stackoverflow、reddit、github等)

import win32gui as win
import time
import uiautomation as auto

while True:
    window = win.GetForegroundWindow()
    win_name = win.GetWindowText(window)
    if "Google Chrome" in win_name:
        chromeControl = auto.ControlFromHandle(window)
        edit = chromeControl.EditControl()
        print('https://' + edit.GetValuePattern().Value)

关于这件事,我几乎试过所有的帖子都没有用。显然chrome已经更改了他们的窗口类名等。任何帮助都将不胜感激。你知道吗


Tags: nameimport脚本urlautoyoutube网站as