我正在尝试使用 win32 使浏览器自动化。 出于公司信息安全考虑,不能使用Selenium。
遇到问题,我无法切换到 win32 中的另一个 iframe。所有元素仅位于第一帧中。 也许有人知道切换框架的方法?
ie = win32com.client.Dispatch("InternetExplorer.Application")
ie.Visible = 1
ie.Navigate(url)
time.sleep(5)
frames = ie.Document.Body.getElemenetsByTagName('iframe')
frames
只有 1 个元素,但还有更多。
如何使用
InternetExplorer.Application
对象在 iframe 之间切换的示例:
import win32com.client
import time
ie = win32com.client.Dispatch("InternetExplorer.Application")
ie.Visible = 1
url = "your_url_here"
ie.Navigate(url)
while ie.Busy:
time.sleep(1)
doc = ie.Document
frames = doc.getElementsByTagName("iframe")
print("Number of iframes:", len(frames))
iframe = frames[0]
doc.parentWindow.frameElement = iframe