我正在尝试在 3 个不同的空格框中插入特定值。但是,我没有找到适用于我正在使用的网站的示例。
Sub Download()
Dim user, password As Variant
Application.ScreenUpdating = False
'Planilha Ativa
Worksheets("Realizado").Activate
'Abrir a página da BMF
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate "http://www.b3.com.br/pt_br/market-data-e-indices/indices/indices-de-segmentos-e-setoriais/serie-historica-do-di.htm"
ie.Visible = True
ie.Document.all.Item("DT_DIA_DE").Value = "02"
ie.Document.all.Item("DT_MES_DE").Value = "01"
ie.Document.all.Item("DT_ANO_DE").Value = "2019"
Application.ScreenUpdating = True
End Sub
最佳答案
Internet Explorer:
它位于 iframe 内。您最初可以直接导航到 iframe 的 src 源
.Navigate2 http://estatisticas.cetip.com.br/astec/series_v05/paginas/lum_web_v05_template_informacoes_di.asp?str_Modulo=completo&int_Idioma=1&int_Titulo=6&int_NivelBD=2
或者,选择 iframe 元素并导航到其 src
Option Explicit
'VBE > Tools > References: Microsoft Internet Controls
Public Sub NavigateLinks()
Dim ie As New InternetExplorer
With ie
.Visible = True
.Navigate2 "http://www.b3.com.br/pt_br/market-data-e-indices/indices/indices-de-segmentos-e-setoriais/serie-historica-do-di.htm"
While .Busy Or .readyState < 4: DoEvents: Wend
.Navigate2 .document.getElementById("bvmf_iframe").src
While .Busy Or .readyState < 4: DoEvents: Wend
With .document
.querySelector("[name='DT_DIA_DE']").Value = "02"
.querySelector("[name='DT_MES_DE']").Value = "01"
.querySelector("[name='DT_ANO_DE']").Value = "2018"
.querySelector("[href*='EnvioChecaDados']").Click
End With
Stop
.Quit
End With
End Sub
XHR(XMLHttpRequest):
页面向此 url 发出 POST 表单 XHR 请求:
http://estatisticas.cetip.com.br/astec/series_v05/paginas/lum_web_v04_10_03_consulta.asp
您可以尝试复制该请求并完全避免使用浏览器。如果您在页面上手动发出请求并通过开发工具(F12 - Chrome)检查网络选项卡,您将找到该网址。 POST 表单参数全部显示,包括日期部分:
点击下载:
.document.querySelector(".primary-text a").click
关于html - 如何通过vba在html空格框中插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56030005/