VBA IE自动化 - 读的iFrame [英] VBA IE Automation - Read iFrame
问题描述
我们的业务使用运营一个基于浏览器的程序。我自动化的解决方案在年底通过这个网站来浏览和检索一些数据。
本身使用常规的框架非常沉重的网站。然而,在我的过程的尽头,它填充我的数据不会成为一个框架,而是一个iFrame。还有非常广泛的javascript整个网站,使事情泥泞。
拼抢的iFrame的src网址开放在新的浏览器错误了网页(即页面显示错误文本,而不是内容)。
我的问题:
如何通过VBA抢出文本的iframe?
我已经试过到目前为止 (随时跳过)的:
的目标在特定的帧中的特定的iFrame,抢的innerHTML 的
随着ie.document.frames(myFrameNum).document.getElementsByTagName(IFRAME)(1).document.body
stringResult = .innerHTML
的目标由ID特定的iFrame在特定的框架,并抓住innerHTML的的
昏暗IFRM作为HTMLIFrame
设置IFRM = ie.document.frames(myFrameNum).document.getElementByID(iFrameID)
Debug.Print iFrm.document.body.innerText
的查找iFrame中的任何实例,并抓住他们的(无结果? - 也许是因为IFRAME是在一个框架镶嵌)
昏暗IFRM作为HTMLIFrame
昏暗的DOC作为HTMLDocument的
对于迭代器= 0〜ie.document.all.Length - 1
如果类型名(ie.document.all(迭代器))=HTMLIFrame然后
设置IFRM = ie.document.all(迭代器)
设置文档= iFrm.document
Debug.Print&安培; doc.body.outerHTML
万一
下一个
试试这个...
昏暗elemCollection作为IHTMLElementCollection设置elemCollection = objDoc.frames(iFrameID)。的document.all
Debug.Print elemCollection.Item(pagemenuli-ADV)。innerText属性
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.
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.
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).
My question:
How can I grab the text out of an iFrame through VBA?
What I've tried so far (feel free to skip):
Target a specific iFrame in a specific frame, and grab innerHTML
With ie.document.frames(myFrameNum).document.getElementsByTagName("iframe")(1).document.body
stringResult = .innerHTML
Target a specific iFrame by ID in a specific frame, and grab innerHTML
Dim iFrm As HTMLIFrame
Set iFrm = ie.document.frames(myFrameNum).document.getElementByID("iFrameID")
Debug.Print iFrm.document.body.innerText
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
Try this...
Dim elemCollection As IHTMLElementCollection
Set elemCollection = objDoc.frames("iFrameID").document.all
Debug.Print elemCollection.Item("pagemenuli-adv").innerText
这篇关于VBA IE自动化 - 读的iFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!