使用vb.net中的GeckoFX浏览器获取Recaptcha2 Iframe HTML但始终为空 [英] Get Recaptcha2 Iframe HTML but always EMPTY using GeckoFX Browser in vb.net

查看:292
本文介绍了使用vb.net中的GeckoFX浏览器获取Recaptcha2 Iframe HTML但始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

这是我的代码:

'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已完全加载并准备就绪,但是我如何以编程方式访问它?

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?

非常感谢

推荐答案

使用 ContentWindow.Document 代替 ContentDocument
您的代码应为:

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

这篇关于使用vb.net中的GeckoFX浏览器获取Recaptcha2 Iframe HTML但始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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