VBA IE 自动化 - 读取 iFrame [英] VBA IE Automation - Read iFrame

查看:55
本文介绍了VBA IE 自动化 - 读取 iFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的业务使用基于浏览器的程序进行运营.我正在自动化一个解决方案来浏览这个网站,并在最后检索一些数据.

Our business uses a browser-based program for operations. I'm automating a solution to navigate through this site, and retrieve some data at the end.

网站本身非常大量地使用常规框架.但是,在我的过程的最后,它不是将我的数据填充到框架中,而是填充到 iFrame 中.整个网站还包含非常广泛的 javascript,使事情变得混乱.

The site itself uses regular frames very heavily. However, at the very end of my process, it populates my data not into a frame, but an iFrame. There's also very extensive javascript throughout the site, making things muddy.

获取 iFrame 的 src URL 并在新浏览器中打开会导致页面出错(即页面显示错误文本而不是内容).

Grabbing the iFrame's src URL and opening in a new browser errors out the page (i.e. the page displays error text instead of the content).

我的问题:

如何通过 VBA 从 iFrame 中抓取文本?

How can I grab the text out of an iFrame through VBA?

到目前为止我尝试过的内容 (可以跳过):

针对特定框架中的特定 iFrame,抓取innerHTML

With ie.document.frames(myFrameNum).document.getElementsByTagName("iframe")(1).document.body
stringResult = .innerHTML

在特定frame中通过ID定位特定iFrame,抓取innerHTML

Dim iFrm As HTMLIFrame
Set iFrm = ie.document.frames(myFrameNum).document.getElementByID("iFrameID")
Debug.Print iFrm.document.body.innerText

找到 iFrame 的任何实例,并抓取它们(没有结果 - 可能是因为 iframe 嵌入在框架中?)

Find any instances of iFrames, and grab them (No results - perhaps because the iframe is embeded in a frame?)

Dim iFrm As HTMLIFrame
Dim doc As HTMLDocument
 For iterator = 0 To ie.document.all.Length - 1
  If TypeName(ie.document.all(iterator)) = "HTMLIFrame" Then
   Set iFrm = ie.document.all(iterator)
   Set doc = iFrm.document
   Debug.Print & doc.body.outerHTML
  End If
Next

推荐答案

我遇到了同样的问题,我使用以下脚本行得到了解决方案..

I faced the same issue and I got the solution using the following line of script..

IE.Document.getElementsbyTagName("iframe")(0).contentDocument.getElementsbyTagName("body")(0).innertext

IE.Document.getElementsbyTagName("iframe")(0).contentDocument.getElementsbyTagName("body")(0).innertext

这篇关于VBA IE 自动化 - 读取 iFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆