【发布时间】:2017-08-20 17:34:10
【问题描述】:
您好:我正在使用 excel 从该网页获取值:https://www2.agenciatributaria.gob.es/es13/h/iexmmmfi.html
如何获取 excel VBA 的代码以获取 NIF、EJF、MOD 和 CEL 的字段?
我尝试使用 getelementbyid("NIF") 和 "name" 但没有结果
谢谢!
上一个帖子:Excel VBA: Get inner text of HTML table td
这是我使用的代码:
Sub AEAT()
Dim IE As Object
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "https://www2.agenciatributaria.gob.es/es13/h/iexmmmfi.html"
Application.Wait (Now + TimeValue("0:00:02"))
IE.Document.getElementById("NIF").Value = Range("A1").Value
Application.Wait (Now + TimeValue("0:00:01"))
IE.Document.getElementById("EJF").Value = "2016"
Application.Wait (Now + TimeValue("0:00:01"))
IE.Document.getElementById("MOD").Value = "347"
Application.Wait (Now + TimeValue("0:00:01"))
IE.Document.getElementById("CEL").Value = Range("a4").Value
Application.Wait (Now + TimeValue("0:00:01"))
IE.Document.getElementById("env_button").Click
End Sub
【问题讨论】:
-
贴出你用过的代码
-
已添加代码。谢谢!
-
您的问题可能更为根本。尝试使用此 URL 打开浏览器,打开控制台(通常按 F12)并输入
document.getElementById('NIF')。你得到某种结果吗?一旦你可以在 VBA 之外成功使用 DOM,在 VBA 中转换代码就相对简单了。 -
另外,我强烈建议您包含您尝试解析的 HTML。就我而言,我运行的是没有 Java 的浏览器,因此看不到您要解析的网页。
-
好的,谢谢。我会做的