【问题标题】:How can I load more results on a web page using VBA?如何使用 VBA 在网页上加载更多结果?
【发布时间】:2017-01-09 18:26:17
【问题描述】:

我想使用 VBA 在以下链接中加载更多结果: http://www.flashscore.com/soccer/england/premier-league/results/

页面的第一次加载只显示了总结果的一半,但我想加载页面中的所有数据。

我想我必须点击“显示更多匹配”链接,但我不知道该怎么做。

谁能帮我出主意?

如果我有更多游戏要加载,并且在第一次点击加载后,更多游戏仍然是隐藏的游戏,我如何才能看到所有游戏?

链接源代码为:

<a href="#" onclick="loadMoreGames(); return false;">Show more matches</a>

您可以在下面找到链接的屏幕截图:

【问题讨论】:

  • 使用getElementsByTagName("a")获取页面上所有链接的集合,然后循环检查innerText是否有“显示更多匹配项” - 在匹配元素上调用click
  • 我的一条建议:Do Until InStr(ie.document.getElementById("preload").getAttribute("Style"), "display: none;") &lt;&gt; 0: DoEvents: Loop 该网站使用各种元素来告知加载状态。 IE.ReadyStateIE.Busy 通常会失败。

标签: vba excel internet-explorer dom web-scraping


【解决方案1】:

您可以在锚节点&lt;a href="#" onclick="loadMoreGames(); return false;"&gt;Show more matches&lt;/a&gt; 中看到分配给onclick 事件的函数名称loadMoreGames(),因此您可以只调用该函数而不是click() 并循环等待加载完成,正如@RyszardJędraszyk 评论的那样:

Sub Test()

    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .Navigate "http://www.flashscore.com/soccer/england/premier-league/results/"
        Do: DoEvents: Loop While .Busy Or .readyState <> 4
        Do: DoEvents: Loop While .Document.readyState <> "complete"
        .Document.parentWindow.execScript "loadMoreGames();"
        Do: DoEvents: Loop While .Document.getElementById("preload").Style.display = "none"
    End With

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 2013-08-16
    相关资源
    最近更新 更多