Веб-слом в Excel - PullRequest
       1

Веб-слом в Excel

0 голосов
/ 28 февраля 2019

Я хочу получить данные из "https://www.oanda.com/currency/converter/" в Excel, используя vba (например, от USD к EUR). Я попытался сделать следующий код ... но он все еще не работает

Sub PullData()

    Dim IE As Object
    Dim doc As HTMLDocument

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True

    IE.Navigate "https://www.oanda.com/currency/converter/"

    Do While IE.Busy Or IE.ReadyState <> 4
        Application.Wait DateAdd("s", 1, Now)
    Loop

    Set doc = IE.Document  

    doc.getElementById("quote_currency_input").Value = "EURO"
    doc.getElementById("base_currency_input").Value = "US Dollar"
           Do While IE.Busy Or IE.ReadyState <> 4
        Application.Wait DateAdd("s", 1, Now)
    Loop

    MsgBox doc.getElementsByClassName("want").Item(0).innerText

    IE.Quit

End Sub

1 Ответ

0 голосов
/ 28 февраля 2019

Вы можете получить из externalHTML или из атрибута значения скрытого элемента

Option Explicit
'VBE > Tools > References:
' Microsoft Internet Controls
Public Sub GetData()
    Dim ie As New InternetExplorer
    With ie
        .Visible = True
        .Navigate2 "https://www.oanda.com/currency/converter/"

        While .Busy Or .readyState < 4: DoEvents: Wend

       .document.getElementById("quote_currency_input").Value = "EURO"
       .document.getElementById("base_currency_input").Value = "US Dollar"
        Debug.Print .document.querySelector("#form_base_amount_input_hidden").Value
        Debug.Print Split(Split(.document.getElementById("form_base_amount_input_hidden").outerHTML, "value=" & Chr$(34))(1), Chr$(34))(0)
        .Quit
    End With
End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...