【发布时间】:2019-02-18 16:29:00
【问题描述】:
我正在寻求帮助以开发在 excel 中运行的 VBA 脚本。
在this 网站,可以为每个基金下载 CSV 文件。我要的 VBA 脚本将:
- 导航到上述网址
- 将资金类型设置为“全部”
- 将可用性设置为“全部”
- 从下拉列表中选择基金提供者
- 点击“过滤资金”按钮
- 点击“下载数据 (.csv)”按钮
需要对“资金提供者”下拉菜单中的每个项目重复此过程。
我在使用 IE 浏览网站方面经验不足,因此不胜感激。我现有的代码如下。它允许我访问 Fund Type 按钮,但我不确定如何更改它的值。
Option Explicit
Sub FidelityCSV()
' Create Internet Explorer object.
Dim BaseURL As String
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
BaseURL = "https://www.fidelity.co.uk/fund-prices/"
IE.Visible = True ' Keep this hidden.
IE.navigate BaseURL
Do While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Wait for it to really finish loading
Application.Wait (Now + TimeValue("0:00:15"))
Dim oHEle 'As IHTMLElementCollection
Dim oHDoc As HTMLDocument
Set oHDoc = IE.document
Set oHEle = oHDoc.getElementById("fund_type")
' Clean up.
IE.Quit
Set IE = Nothing
Set oHEle = Nothing
Set oHDoc = Nothing
End Sub
【问题讨论】:
标签: html excel vba web-scraping