html - 无法从网站冗余下拉列表中选择或更新
问题描述
我是 VBA 的新手,正在尝试使用 VBA 自动选择网站菜单。该网站有一些我无法成功更改或更新的下拉菜单。我已经尝试过该网站的早期建议,但没有任何成功。网站上的其他值可以填.value = xxx,但是下拉有点难。
该网站是(https://worldfreightrates.com/en/freight)。
该部分的 HTML 是这样的:
<div id="fcl" style="display: block;">
<p>Container Type</p>
<div class="dk_container dk_theme_default" id="dk_container_containerLoadType"tabindex=""style="display: block;">
<a class="dk_toggle">
<span class="dk_label">20 FT</span>
</a>
<div class="dk_options" style="top: 29px;">
<ul class="dk_options_inner">
<li class="dk_option_current">
<a data-dk-dropdown-value="20">20 FT</a></li>
<li class="">
<a data-dk-dropdown-value="40">40 FT</a></li>
<li class="">
<a data-dk-dropdown-value="45">45 FT</a></li>
</ul>
</div>
</div>
<select name="value" class="dropkick" id="containerLoadType" style="display: none;">
<option value="20">20 FT</option>
<option value="40" selected="true">40 FT</option>
<option value="45">45 FT</option>
</select>
</div>
Here is my code:
```
Option Explicit
Public Sub dropdown()
Dim wb As Excel.Workbook
Set wb = ThisWorkbook
Dim ws As Excel.Worksheet
Set ws = wb.Worksheets("sheet1")
Dim ie As New SHDocVw.InternetExplorer
Dim doc As HTMLDivision
Dim htmldc As MSHTML.HTMLDocument
Dim x As Long, y As Long
Dim ur As String
Application.ScreenUpdating = False
On Error Resume Next
ur = "https://worldfreightrates.com/en/freight"
ie.Visible = True
ie.navigate ur
x = 0
y = 0
Do While ie.readyState <> 4: DoEvents: Loop
Do Until ie.readyState = 4: DoEvents: Loop
While ie.Busy
DoEvents
Wend
Set htmldc = ie.document
Dim dk_open As Object
Dim cont As Object
Set cont = htmldc.getElementById("dk_container_containerloadtype")
Dim label As Object
Dim toggle As Object
Set toggle = cont.getElementsByClassName("dk_toggle")
Toggle.item.click
'toggle.item.click opens dropdown menu
toggle.Item.Click
toggle.Item(0).Value = "20 FT"
toggle.selectedIndex = 0
Set label = htmldc.getElementsByClassName("dk_label")
Dim opts As Object, opt As Object
Set opts = htmldc.getElementById("containerLoadType")
opts.Item(0).Value = "0"
opts.Item(0).FireEvent ("onChange")
For Each opt In opts
Debug.Print (opt.innerText)
If InStr(opt.innerText, "20") Then
y = x
opts.Item(0).selectedIndex = y
opt.Item(0).Click
opt.initEvent "change", True, False
opt.Selected = True
label.Value = opt.innerText
label.selectedIndex = y
End If
x = x + 1
Next opt
Dim dk_opts As Object, dk_opt As Object
Set dk_opts = htmldc.getElementById
("dk_container_containerLoadType").getElementsByTagName("li
")
For Each dk_opt In dk_opts
'Debug.Print (dk_opt.innerText)
If InStr(dk_opt.innerText, "20") Then
'below items do not change selection
dk_opt.Item(0).selectedindex = y
dk_opt.Click
dk_opt.Selected = True
End If
Next dk_opt
handler:
ie.Quit
Set ie = Nothing
Exit Sub
ie.Quit
Set ie = Nothing
Application.ScreenUpdating = True
End Sub
```
问题:我可以打开菜单,然后从那里循环浏览选项表,直到找到所需的选项。之后,我不确定如何将值放入下拉菜单或选择值后如何更新网页。没有出现任何错误,只是没有从我所知道的中选择该值。我尝试过使用以下内容:
```
opts.Item(0).Value = "0"
opts.Item(0).FireEvent ("onChange")
opts.selectedindex= 0
opts.selection = true
```
谁能指出正确的方向或告诉我我的代码是否有问题?任何建议,将不胜感激。
解决方案
不是最好的解决方案,但我希望这会有所帮助请参考输入表的附件图像,从那里填充字段。
我也是新手,所以可能会有更好更短的做事方式
这是代码 -
Sub World_Freight_Rates()
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True 'Let's see the browser window
ie.navigate "https://worldfreightrates.com/en/freight"
Do While ie.Busy 'We need to wait until the page has loaded
Application.Wait DateAdd("s", 1, Now)
Loop
lr = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lr
Var = Cells(x, 1).Value
'Get Window ID for IE so we can set it as activate window
HWNDSrc = ie.HWND
'Set IE as Active Window
SetForegroundWindow HWNDSrc
Set OP = ie.document.getElementById("fromNameOcean")
OP.Focus
'SendKeys "Portland", True 'Type Out
OP.Value = ThisWorkbook.Sheets("Sheet2").Range("A" & x).Value 'Set the textbox value Range
'Wait for the Dropdown to Load
Application.Wait (Now + TimeValue("0:00:05"))
Application.SendKeys "{DOWN}", True 'Hit Down Arrow
Application.SendKeys "~", True 'Hit "ENTER", to make it work IE window should be active & up top
Set DP = ie.document.getElementById("toNameOcean")
DP.Focus
'SendKeys "New York", True 'Type Out
DP.Value = ThisWorkbook.Sheets("Sheet2").Range("B" & x).Value 'Set the textbox value Range
'Wait for the Dropdown to Load
Application.Wait (Now + TimeValue("0:00:05"))
Application.SendKeys "{DOWN}", True 'Hit Down Arrow
Application.SendKeys "~", True 'Hit "ENTER", to make it work IE window should be active & up top
Set SC = ie.document.getElementsByClassName("dk_toggle") 'Id("dk_container_commodityNameOcean")
'MsgBox SC(0).innerText
SC(17).Click
If ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Agriculture (Fruits and Vegetables)" Then
Application.SendKeys "{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Apparel" Then
Application.SendKeys "{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Automobiles & Motorcycles" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Automobile & Motorcycle Parts" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Arts & Crafts" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Beauty & Personal Care" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Chemicals" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Computer Hardware & Software" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Construction Equipment" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Construction Materials" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Consumer Electronics" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Electrical Equipment & Supplies" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Electronic Components & Supplies" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Fashion Accessories" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Bottled Beverages" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Bottled Products (Non-beverages)" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Food (Perishable)" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Food (Non-Perishable) i.e. Cereals and Grains" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Food (Frozen)" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Food (Frozen Meat)" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Furniture (New Branded)" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Furniture (Used)" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Hardware" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Health & Medical Supplies" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Home Appliances" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Home & Garden" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Household Goods" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Lights & Lighting" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Luggage, Bags & Cases" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Mechanical & Fabrication Parts" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Machinery" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Measurement & Analysis Instruments" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Minerals & Metallurgy" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Office & School Supplies" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Packaging & Printing" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Rubber & Plastics" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Security & Protection" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Shoes & Accessories" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Sports & Entertainment" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Telecommunications" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Textiles & Leather Products" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Timepieces, Jewelry, Eyewear" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Tools" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Toys & Hobbies" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "Transportation" Then
Application.SendKeys "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}", True
Application.SendKeys "~", True
End If
Set CV = ie.document.getElementById("commodityValueOcean")
CV.Value = ThisWorkbook.Sheets("Sheet2").Range("D" & x).Value
Set CT = ie.document.getElementsByClassName("dk_toggle")
CT(18).Click
If ThisWorkbook.Sheets("Sheet2").Range("E" & x).Value = "20" Then
Application.SendKeys "{UP}", True
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("E" & x).Value = "40" Then
Application.SendKeys "~", True
ElseIf ThisWorkbook.Sheets("Sheet2").Range("C" & x).Value = "45" Then
Application.SendKeys "{DOWN}", True
Application.SendKeys "~", True
End If
Set GR = ie.document.getElementsByClassName("submit")
GR(5).Click
'Wait for the Result to Load
Application.Wait (Now + TimeValue("0:00:03"))
Set CMRE = ie.document.getElementsByClassName("result")
'MsgBox CMRE(0).innerText
Range("F" & x).Value = CMRE(0).innerText
'Set NT = ie.document.getElementsByClassName("smcx-btn smcx-btn-secondary smcx-pull-left")
'NT.Click
Next
ie.Quit
Set ie = Nothing
End Sub
推荐阅读
- javascript - 使用解构的动态命名值
- c# - 分配引用类型属性时的最佳实践
- java - 使用 JPA 的 LocalDate 无法正常工作
- scala - 如何在scala中使用拆分功能
- typescript - nb-select 没有清除 form.reset 上的选择
- python-3.x - __init__.py 导入模块中的 Python 错误
- azure-devtest-labs - 是否可以在 Azure Windows Server DSVM 上创建自定义的基于 Linux 的 Docker 映像
- arrays - 显示数组的特定部分?[SwiftUI]
- performance - 通过 std::vector 的矩阵乘法比 numpy 慢 10 倍
- r - 使用 R 过滤每列的最大值并输出为 df