在vba中获取iframe的Contentwindow-访问被拒绝/权限被拒绝

Irf*_*ikh 5 excel iframe vba excel-vba

我陷入了使用vba访问iframe的contentwindow的问题。使用iframe.domain = document.domain进行检查时,框架位于相同的域中。以下是到目前为止我尝试过的。我阅读了所有网站,但找不到解决方法。简化同一域/跨域消息传递的任何其他方法都是高度可取的。


Dim ie As New InternetExplorer   
Dim objshell, objshellwindows
Dim doc As MSHTML.HTMLDocument
Dim doc1 As MSHTML.IHTMLDocument
Dim iframe As MSHTML.HTMLIFrame


Set objshell = CreateObject("Shell.Application")
Set objshellwindows = objshell.Windows

For Each ie In objshellwindows

If InStr(ie.LocationURL, "http://www.example.com/examples/camera/html/index.html") > 0 Then
    Set doc = ie.document

    For Each iframe In doc.getElementsByTagName("IFRAME")
        Set doc1 = iframe.contentWindow.document  '---Access Denied/ Permission Denied Error
    Next

End If
Next

Rys*_*zyk 0

有时,由于同源策略,您将无法访问这样的 IFrame 。您可以使用 RegEx 或更好的方式从响应文本中获取数据 - 使用 IFrame 属性中的链接src发送请求并直接获取其内容。