Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 在iframe中引用HTML文档时遇到问题_Excel_Vba_Recaptcha - Fatal编程技术网

Excel 在iframe中引用HTML文档时遇到问题

Excel 在iframe中引用HTML文档时遇到问题,excel,vba,recaptcha,Excel,Vba,Recaptcha,我在尝试引用包含recaptcha的iframe内的元素时遇到了一些问题 我的脚本的目标是帮助用户填写搜索表单,单击“搜索”,指导用户处理reCaptcha(我不想破坏captcha,或类似的东西),然后在搜索后,打开找到的页面以获取一些信息并显示给用户确认 问题是,当我以编程方式单击Search按钮时,reCaptcha脚本将起作用。有时,它会清除访问权限并识别请求是由人发出的(当用户在使用脚本之前正在做其他事情时);其他时候,如果您是人类,它会显示带有图像测试的reCaptcha弹出窗口 我

我在尝试引用包含recaptcha的iframe内的元素时遇到了一些问题

我的脚本的目标是帮助用户填写搜索表单,单击“搜索”,指导用户处理reCaptcha(我不想破坏captcha,或类似的东西),然后在搜索后,打开找到的页面以获取一些信息并显示给用户确认

问题是,当我以编程方式单击Search按钮时,reCaptcha脚本将起作用。有时,它会清除访问权限并识别请求是由人发出的(当用户在使用脚本之前正在做其他事情时);其他时候,如果您是人类,它会显示带有图像测试的reCaptcha弹出窗口

我需要区分reCaptcha脚本何时自动识别或显示验证码图像,因为在后一种情况下,我将显示一个弹出窗口,告诉用户去处理验证码

问题是:我可以识别reCaptcha iframe(保存在变量
ifrCaptcha
中);我还知道何时通过包含iframe(
ifrCaptcha.parentElement.parentElement.style.visibility
)的
div的可见性CSS样式显示挑战。但是我还没有找到一种方法来引用iframe中包含的文档

当我使用
ifrCaptcha.document
时,它获取页面的主文档,而不是iframe文档

我如何引用iframe文档

该页面不是公开的,但我认为任何带有reCaptcha的页面都可以做到这一点;代码如下(目标仅指iframe文档中的任何内容;例如,iframe文档的标题):

Sub-AbrePesquisa()
Dim IE作为InternetExplorer,DocHTML作为HTMLDocument,ifrDocHTML作为HTMLDocument
作为整数的Dim intCont
将ifrCaptcha设置为HTMLIFrame
Dim bolCaptchaValidado为布尔值,bolCaptchaVisivel为布尔值
Set IE=新的InternetExplorer
即“导航”http://www.whatever-url-which-uses-recaptcha.com"
做
多芬特
循环直到IE.readyState=readyState\u完成
设置tml=IE.document
设置ifrCaptcha=Nothing
设置ifrCaptcha=PegarCaptcha(DOCTML)
strrccaptcha=ifrCaptcha.src'当页面重新加载时,iframe src会发生一些变化,所以我需要它
DocHTML.getElementById(“SearchString”).Value=strSearchParameters
DocHTML.getElementById(“搜索按钮”)。单击
'等待浏览器处理reCaptcha脚本
做
设置ifrCaptcha=Nothing
设置ifrCaptcha=PegarCaptcha(DOCTML)
bolCaptchaVisivel=ExibindoCaptcha(DocHTML,ifrCaptcha)
如果bolCaptchaVisivel=False,则
如果strrccaptcha ifrCaptcha.src,则bolCaptchaValidado=True
如果结束
循环直到bolCaptchaValidado=True或bolCaptchaVisivel=True
设置ifrDocHTML=ifrCaptcha.document
Debug.Print ifrDocHTML.Title'返回主页标题
“Debug.Print ifrDocHTML.InnerHtml”返回主页HTML
端接头
函数ExibindoCaptcha(DocHTML作为HTMLDocument,ifrCaptcha作为HTMLIFrame)作为布尔值
如果ifrCaptcha什么都不是,那么
ExibindoCaptcha=False
ElseIf ifrCaptcha.parentElement为Nothing,则“我正在处理的页面的验证码位于嵌套在另一个div中的div中,当reCaptcha未显示时,VBA会将这两个验证码返回为不存在(即使我看到这两个验证码都存在于浏览器中,在Inspector模式下)
ExibindoCaptcha=False
ElseIf ifrCaptcha.parentElement.parentElement则为空
ExibindoCaptcha=False
其他的
如果ifrCaptcha.parentElement.parentElement.Style.visibility=“可见”,则
ExibindoCaptcha=True
其他的
ExibindoCaptcha=False
如果结束
如果结束
端函数
函数PegarCaptcha(作为HTMLDocument的DocHTML)作为HTMLIFrame
作为HTMLIFrame的Dim ifrCont
对于DocHTML.getElementsByTagName(“iframe”)中的每个ifrCont
如果ifrCont.Title=“desafio reCAPTCHA”,则退出
下一个ifrCont
如果ifrCont什么都不是,那么
设置PegarCaptcha=无
其他的
设置PegarCaptcha=ifrCont
如果结束
端函数
有人能帮我查一下Captcha iframe中的文档吗


提前感谢您的帮助

难道CAPTCHA不应该存在以防止人们自动化这些东西吗?你问的是如何使它们自动化?还是我遗漏了什么?不完全是,有三个原因。首先,我的应用程序不会发出先发制人的、过度的或自主的请求——它不会自动使用,只会帮助用户完成填空表单中令人厌烦的部分。其次,它不直接向服务器发出请求。相反,它打开浏览器并模拟人工用户单独进行的操作。第三(也是最后一点),由于上述原因,它不会使服务器过载。(继续…)(继续)。这更像是相反的:这些信息无论如何都必须收集和注册,而这些活动通常是由人类用户手工完成的。人类在没有机器帮助的情况下这样做最终会犯错误,这可能会导致以后的失败,并导致新的访问相同的网站以纠正这些错误。我与系统管理员保持密切联系;因为这些原因,他们知道我的活动,这并不困扰他们。验证码是用来防止人们提出过多的请求(我的应用程序只执行必要的请求)。最后,系统管理员不必担心我会像我那样删除数据,但他们也不愿意开发任何API或其他方式来删除没有验证码的数据。不管怎样,数据都会被废弃(这就是系统存在的原因)——这可以由人工单独完成,导致错误、打字错误等,或者由人工监视AIs,我认为这样做更好,也更不容易导致错误。对m
Sub AbrePesquisa()

    Dim IE As InternetExplorer , DocHTML As HTMLDocument, ifrDocHTML As HTMLDocument
    Dim intCont As Integer
    Dim ifrCaptcha As HTMLIFrame
    Dim bolCaptchaValidado As Boolean, bolCaptchaVisivel As Boolean


    Set IE = New InternetExplorer
    IE.Navigate "http://www.whatever-url-which-uses-recaptcha.com"

    Do
        DoEvents
    Loop  Until IE.readyState = READYSTATE_COMPLETE

    Set DocHTML = IE.document

    Set ifrCaptcha = Nothing
    Set ifrCaptcha = PegarCaptcha(DocHTML)
    strSrcCaptcha = ifrCaptcha.src ' When page reloads, the iframe src changes a bit, so I need it

    DocHTML.getElementById("SearchString").Value = strSearchParameters
    DocHTML.getElementById("SearchButton").Click

    ' Wait for browser to process the reCaptcha script
    Do
        Set ifrCaptcha = Nothing
        Set ifrCaptcha = PegarCaptcha(DocHTML)

        bolCaptchaVisivel = ExibindoCaptcha(DocHTML, ifrCaptcha)

        If bolCaptchaVisivel = False Then
            If strSrcCaptcha <> ifrCaptcha.src Then bolCaptchaValidado = True
        End If

    Loop Until bolCaptchaValidado = True Or bolCaptchaVisivel = True

    Set ifrDocHTML = ifrCaptcha.document

    Debug.Print ifrDocHTML.Title ' Returns the main page title
    Debug.Print ifrDocHTML.InnerHtml ' Returns the main page HTML

End Sub

Function ExibindoCaptcha(DocHTML As HTMLDocument, ifrCaptcha As HTMLIFrame) As Boolean

    If ifrCaptcha Is Nothing Then
        ExibindoCaptcha = False

    ElseIf ifrCaptcha.parentElement Is Nothing Then ' The page I'm working in has the captcha inside a div nested in another div, both of which VBA returns as non-existing when reCaptcha isn't showing (even I seeing both exists in browser, in Inspector mode)
        ExibindoCaptcha = False

    ElseIf ifrCaptcha.parentElement.parentElement Is Nothing Then
        ExibindoCaptcha = False

    Else
        If ifrCaptcha.parentElement.parentElement.Style.visibility = "visible" Then
            ExibindoCaptcha = True
        Else
            ExibindoCaptcha = False
        End If
    End If

End Function

Function PegarCaptcha(DocHTML As HTMLDocument) As HTMLIFrame

    Dim ifrCont As HTMLIFrame

    For Each ifrCont In DocHTML.getElementsByTagName("iframe")
        If ifrCont.Title = "desafio reCAPTCHA" Then Exit For
    Next ifrCont

    If ifrCont Is Nothing Then
        Set PegarCaptcha = Nothing

    Else
        Set PegarCaptcha = ifrCont

    End If

End Function