我正在尝试从所有正在运行的 IE 实例中获取一些数据以从页面源中挂钩记录的用户名,我尝试使用 selenium 让用户从 selenium 运行 IE,然后当用户登录时我得到用户名,它有点工作仅在第一个选项卡中,如果用户从另一个窗口/选项卡转到登录页面,我无法理解。看起来带有 IE window_handles 的 selenium 不能很好地工作。在谷歌上搜索我可能会发现对我来说更好的东西,它可以从所有正在运行的选项卡/窗口中的股票 Internet Explorer 中获取一些数据。在这个链接之后,我能够获得页面标题和位置 URL,它还解释了如何使页面导航到另一个 URL。现在我找不到的是如何获取页面源。
from win32com.client import Dispatch
from win32gui import GetClassName
ShellWindowsCLSID = '{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
ShellWindows = Dispatch ( ShellWindowsCLSID )
for sw in ShellWindows :
if GetClassName ( sw . HWND ) == 'IEFrame' :
print(sw)
print(sw.LocationName)
print(sw.LocationURL)
#sw.Document.Location = "http://python.org" navigating to another url
print(50 * '-')