Javascript VBA动态网页抓取Excel

Javascript VBA动态网页抓取Excel,javascript,excel,vba,iframe,web-scraping,Javascript,Excel,Vba,Iframe,Web Scraping,我有一个关于如何从该网页中获取数据的问题: 它似乎保存在iframe中,屏幕上出现了一堆javascripting 当我试图收集iframe下的span、div或tr标记中的元素时,我似乎无法收集其中的数据 我的目标是保存在class=“pane legend item value pane legend line main”元素中的innertext 显然,innertext将根据特定时间光标在屏幕上的位置而变化。所以我试着做的是设置一个IE,它已经加载了页面,光标在正确的位置,在图表的末尾

我有一个关于如何从该网页中获取数据的问题:

它似乎保存在iframe中,屏幕上出现了一堆javascripting

当我试图收集iframe下的span、div或tr标记中的元素时,我似乎无法收集其中的数据

我的目标是保存在class=“pane legend item value pane legend line main”元素中的innertext

显然,innertext将根据特定时间光标在屏幕上的位置而变化。所以我试着做的是设置一个IE,它已经加载了页面,光标在正确的位置,在图表的末尾(给我最后的数据点),你可以把光标从屏幕上移开,然后我写了一些简单的代码来抓取IE窗口,然后尝试GetElements,正是在这一点上,我无法获得任何数据

这是我迄今为止的代码,非常粗糙,因为我一直在尝试编辑,因为我阅读了更多的选项,但没有获得任何胜利:(…任何想法或帮助将不胜感激!(屏幕截图也在底部)

excel在另一个屏幕上打开excel和VB时可以找到并与之对话的现有IE的屏幕截图,以及我想要刮取的数据

我真的很难从该页面处理两个嵌套的
iFrame
,以收集所需的内容。但无论如何,我最终解决了它。运行以下代码并获取您请求的内容:

Sub forexpros()
    Dim IE As New InternetExplorer, html As HTMLDocument
    Dim frm As Object, frmano As Object, post As Object

    With IE
        .Visible = True
        .navigate "http://tvc4.forexpros.com/init.php?family_prefix=tvc4&carrier=64694b96ed4909e815f1d10605ae4e83&time=1513525898&domain_ID=70&lang_ID=70&timezone_ID=31&pair_ID=171&interval=86400&refresh=4&session=session&client=1&user=200743128&width=650&height=750&init_page=instrument&m_pids=&watchlist=&site=https://au.investing.com&version=1.11.2"
        Do Until .readyState = READYSTATE_COMPLETE: Loop
        Application.Wait (Now + TimeValue("0:00:05"))
        Set frm = .document.getElementsByClassName("abs") ''this is the first iframe
        .navigate frm(0).src
        Do Until .readyState = READYSTATE_COMPLETE: Loop
        Application.Wait (Now + TimeValue("0:00:05"))
        Set html = .document
    End With

    Set frmano = html.getElementsByTagName("iframe")(0).contentWindow.document  ''this is the second iframe

    For Each post In frmano.getElementsByClassName("pane-legend-item-value pane-legend-line main")
        Debug.Print post.innerText
    Next post
    IE.Quit
End Sub
Sub forexpros()
    Dim IE As New InternetExplorer, html As HTMLDocument
    Dim frm As Object, frmano As Object, post As Object

    With IE
        .Visible = True
        .navigate "http://tvc4.forexpros.com/init.php?family_prefix=tvc4&carrier=64694b96ed4909e815f1d10605ae4e83&time=1513525898&domain_ID=70&lang_ID=70&timezone_ID=31&pair_ID=171&interval=86400&refresh=4&session=session&client=1&user=200743128&width=650&height=750&init_page=instrument&m_pids=&watchlist=&site=https://au.investing.com&version=1.11.2"
        Do Until .readyState = READYSTATE_COMPLETE: Loop
        Application.Wait (Now + TimeValue("0:00:05"))
        Set frm = .document.getElementsByClassName("abs") ''this is the first iframe
        .navigate frm(0).src
        Do Until .readyState = READYSTATE_COMPLETE: Loop
        Application.Wait (Now + TimeValue("0:00:05"))
        Set html = .document
    End With

    Set frmano = html.getElementsByTagName("iframe")(0).contentWindow.document  ''this is the second iframe

    For Each post In frmano.getElementsByClassName("pane-legend-item-value pane-legend-line main")
        Debug.Print post.innerText
    Next post
    IE.Quit
End Sub