Excel中VBA:等待在Internet Explorer中的JavaScript执行 [英] Excel VBA: Wait for JavaScript execution in Internet Explorer

查看:415
本文介绍了Excel中VBA:等待在Internet Explorer中的JavaScript执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些网页在Excel VBA中拼抢。下面是我遇到的麻烦的code部分:

I am trying to do some web scraping in Excel VBA. Here is the part of the code that I am having trouble with:

IE.Navigate URL
Do
  DoEvents
Loop While IE.ReadyState <> 4 Or IE.Busy = True
Set doc = IE.document

运行此文档后,包含仍然在它未执行使用JavasScript HTML。
这是还没有被执行的脚本的签名:

After running this doc contains html that still has unexecuted JavasScript in it. This is the signature of the script that has not been executed:

<SCRIPT type=text/javascript>
        goosSearchPage.Initialize(...)...;
</SCRIPT>

我可以通过做等待执行 Application.Wait(现在+ TIMEVALUE(X)),但是这确实是不尽如人意,随着时间的量剧本花费执行是相当变数,取决于输入。

I can wait for execution by doing Application.Wait(Now + TimeValue(x)) but that really is not satisfactory, as the amount of time the script takes to execute is quite variable depending on input.

有没有办法要么等待脚本来完成评估或干脆直接在商务部评估脚本对象?

Is there a way to either wait for the script to finish evaluating or to just evaluate the script directly in the doc object?

推荐答案

实际上,你可以用评估IE窗口的JavaScript函数。但你得建立一个回调,因为函数将被评估异步。

You actually can evaluate the javascript function with the ie window. But you gotta set up a Callback because the function will be evaluated async.

这篇关于Excel中VBA:等待在Internet Explorer中的JavaScript执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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