无法通过VBA在Internet Explorer中选择下拉列表

问题描述 投票:0回答:1

我正在尝试从此网站上的列表中选择货币:https://www1.oanda.com/currency/converter/

问题是值被输入到这些字段中,选择基本上是货币,但是当我们手动输入时会刷新。通过宏,可以输入值,但是不会发生javascript或背景值转换的任何背景。我不能使用任何其他网站进行货币换算。任何帮助将不胜感激。

货币值(在excel工作表中)导出为curr1,curr2变量

这里是密码

'Option Explicit
Sub converter()

Dim ie As Object
Dim doc As HTMLDocument
Dim inputval, returnval As String
Dim starttime As Double
starttime = Timer
Dim Curr1, Curr2 As String
Dim i As Integer
Dim mywb As Workbook
Dim myws As Worksheet
Set mywb = ThisWorkbook
Set myws = mywb.Worksheets("Ui")

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

'Navigating to the URL
ie.navigate "https://www1.oanda.com/currency/converter/"

'Letting the browser fully load
Do While ie.Busy Or ie.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop


Set doc = ie.document
Range(Cells(4, 9), Cells(Rows.Count, 9)).ClearContents

Do While myws.Cells(4 + i, 4).Value <> ""

Curr1 = myws.Cells(4 + i, 5).Value
Curr2 = myws.Cells(4 + i, 7).Value
inputval = myws.Cells(4 + i, 8).Value


'ENTERRING CURRENCY VALUES
doc.getElementById("quote_currency_input").Value = Curr1
doc.getElementById("base_currency_input").Item.innerText = Curr2

'ENTERING VALUE TO BE CONVERTED
returnval = doc.getElementById("base_amount_input").Value


'Do While IE.Busy Or IE.readyState <> 4
Application.Wait (Now + TimeValue("0:00:05"))
'Loop


myws.Activate
myws.Cells(4 + i, 9).Value = returnval


i = i + 1
Loop

'IE.Quit
'MsgBox "Currencies have been converted" & vbNewLine & "Time Taken - " & Format((Timer - starttime) / 86400, "hh:mm:ss")
End Sub
html excel vba web-scraping browser-automation
1个回答
0
投票

多么挑战!我当然不是最没有经验的人,但也绝对不是最好的人。

© www.soinside.com 2019 - 2024. All rights reserved.