【问题标题】:Get Recaptcha2 Iframe HTML but always EMPTY using GeckoFX Browser in vb.net在 vb.net 中使用 GeckoFX 浏览器获取 Recaptcha2 Iframe HTML 但始终为空
【发布时间】:2016-07-10 11:17:42
【问题描述】:

我正在为 vb.net 使用最新的 GeckoFX-45 浏览器。

我的问题: 我无法获取 iframe 的 HTML。

这是我的代码:

'Open Recaptcha2 test site
Browser.Navigate("http://patrickhlauke.github.io/recaptcha/")
'Wait for loading (all ways I know)
Browser.NavigateFinishedNotifier.BlockUntilNavigationFinished()
Dim maxTimeouttime As DateTime = DateTime.Now.AddSeconds(4)
While DateTime.Now < maxTimeouttime
System.Windows.Forms.Application.DoEvents()
System.Threading.Thread.Sleep(100)
End While
While Browser.IsBusy()
System.Windows.Forms.Application.DoEvents()
System.Threading.Thread.Sleep(100)
End While   

'Getting the HTML of the Iframe is always empty:
For Each _E As GeckoIFrameElement In Browser.DomDocument.GetElementsByTagName("iframe")
If _E.GetAttribute("title") = "recaptcha widget" Then
Dim html = _E.ContentDocument '-> is empty  
Dim html2  = _E.OuterHtml '-> HTML does not include the content of the Iframe 
Exit For
End If
Next

该网站在浏览器中显示得非常好,recaptcha2 iframe 已完全加载并准备就绪,但我如何以编程方式访问它?

非常感谢

【问题讨论】:

    标签: vb.net iframe captcha recaptcha geckofx


    【解决方案1】:

    使用ContentWindow.Document 代替ContentDocument。 你的代码应该是:

    Dim iFr_dom As GeckoDomDocument
    Dim iFr_html As String
    For Each iFr As GeckoIFrameElement In Browser.DomDocument.GetElementsByTagName("iframe")
        If iFr.GetAttribute("title") = "recaptcha widget" Then
            iFr_dom = iFr.ContentWindow.Document
    
            'DomDocument has no OuterHtml property so we use
            iFr_html = iFr_dom.GetElementsByTagName("BODY")(0).OuterHtml
            'Or if the above not work, use the code below
            'iFr_html = iFr_doc.GetElementsByTagName("body")(0).OuterHtml
            Exit For
        End If
    Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-22
      相关资源
      最近更新 更多