Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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
Javascript VBA/Internet Explorer:从OnClick事件捕获结果URL_Javascript_Excel_Vba_Internet Explorer_Browser Automation - Fatal编程技术网

Javascript VBA/Internet Explorer:从OnClick事件捕获结果URL

Javascript VBA/Internet Explorer:从OnClick事件捕获结果URL,javascript,excel,vba,internet-explorer,browser-automation,Javascript,Excel,Vba,Internet Explorer,Browser Automation,我正在使用VBA中的Internet Explorer对象自动化一些数据收集,并且在尝试获取由href onclick事件生成的url时遇到了麻烦 下面的代码正在“单击”链接,这将使我进入另存为对话框。相反,我只想获取onclick事件生成的结果url。由于href属性指向javascript:void(0),因此我无法从标记中提取此内容 我知道IE本身知道生成的url,因为如果我手动下载生成的文件,我可以从下载窗口检查这一点,但是有没有一种方法可以通过编程方式访问和捕获(以字符串形式)触发的o

我正在使用VBA中的Internet Explorer对象自动化一些数据收集,并且在尝试获取由href onclick事件生成的url时遇到了麻烦

下面的代码正在“单击”链接,这将使我进入另存为对话框。相反,我只想获取onclick事件生成的结果url。由于href属性指向javascript:void(0),因此我无法从
标记中提取此内容

我知道IE本身知道生成的url,因为如果我手动下载生成的文件,我可以从下载窗口检查这一点,但是有没有一种方法可以通过编程方式访问和捕获(以字符串形式)触发的onclick事件将IE定向到的url?实际上没有IE尝试下载文件本身

Set Link = IE.document.getElementsByTagName("a")

For Each l In Link
    If l.innertext = "Excel" Then
       l.FireEvent ("onclick")
    Exit For
    End If
Next l
也许对你有帮助

Sub tst()

    Dim ie As New SHDocVw.InternetExplorer
    Dim ieDOC As HTMLDocument
    Dim ieONC As IHTMLElement
    Dim ieONCs As IHTMLElementCollection

    ie.navigate "[your url]"
    ie.Visible = True
    Do: DoEvents: Loop Until ie.readyState = READYSTATE_COMPLETE
    Do: DoEvents: Loop While ie.Busy = True

    Set ieDOC = ie.document
    Set ieONCs = ieDOC.getElementsByClassName("[class]")

    For Each ieONC In ieONCs

        Debug.Print ieONC.onclick

    Next

End Sub

也许吧,但是如果没有相关的HTML,很难说。url是公共的吗?不确定,OnClick事件中的逻辑和代码是什么。仅凭你的上述描述是很难猜测的。VBA代码对再现问题没有帮助。如果你在该网站上发布HTML和JS代码,这将更好地再现我们这边的问题。然后我们可以用它做一个测试,看看它在正常情况下是如何工作的,我们可以检查是否有可能自动化您的需求。如果要自动执行“保存文件”对话框,此链接可能会对您有所帮助。