Python:从Google Chrome获取主动选项卡URL
我可以找到旧的答案,但没有一个适用于 python 3.9.10 和 Chrome 100.0.4896.88
这是不起作用的代码之一。今天我们有什么办法可以做到这一点吗? 如果有人可以提供适用于 Windows 10 操作系统的通用信息,欢迎。
from win32gui import GetForegroundWindow
from win32process import GetWindowThreadProcessId
from pywinauto.application import Application
window = GetForegroundWindow()
tid, pid = GetWindowThreadProcessId(window)
app = Application().connect(process=pid)
dlg = app.top_window()
title = "Address and search bar"
url = dlg.child_window(title=title, control_type="Edit").get_value()
print(url)
I could find old answers but none of them working for python 3.9.10 and Chrome 100.0.4896.88
This is one of the code that is not working. Is there any way we can do that today?
If anyone can give generic information that applies to windows 10 os, its welcome.
from win32gui import GetForegroundWindow
from win32process import GetWindowThreadProcessId
from pywinauto.application import Application
window = GetForegroundWindow()
tid, pid = GetWindowThreadProcessId(window)
app = Application().connect(process=pid)
dlg = app.top_window()
title = "Address and search bar"
url = dlg.child_window(title=title, control_type="Edit").get_value()
print(url)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您在时间结束之前单击镀铬窗口。
The following code works as long as you click on the Chrome window before the end of the time.sleep(3) :