Get Recaptcha2 Iframe HTML but always EMPTY using GeckoFX Browser in vb.net

本秂侑毒 提交于 2019-12-24 12:05:07

问题


I am using the latest GeckoFX-45 Browser for vb.net.

My problem: I can not get the HTML of the Iframe.

Here is my code:

'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

The site is displayed very well in the Browser and the recaptcha2 iframe is loaded completly and ready but how can I access it programatically?

Thank you very much


回答1:


Use ContentWindow.Document instead of ContentDocument. Your code shoud be:

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


来源:https://stackoverflow.com/questions/35243259/get-recaptcha2-iframe-html-but-always-empty-using-geckofx-browser-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!