0

id 下的内部文本未打印。

Sub JJ()

Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim HEL, HBE As MSHTML.IHTMLElement
Dim HBEs As MSHTML.IHTMLElementCollection
Dim ha, hb, hc, hd, he, hf, hg, hh, hi, hj As String
Dim i, x As Integer

IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=MCX"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop

Set hdoc = IE.document
ha = hdoc.getElementById("quoteLtp").innerText

Debug.Print ha
End Sub

它只是什么也没显示。请在那里帮助我解决问题。

4

1 回答 1

0

我已dim在您的代码中添加了新内容,提取 1,536 的值没有问题,请尝试查看

Sub JJ()

Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim HEL, HBE As MSHTML.IHTMLElement
Dim HBEs As MSHTML.IHTMLElementCollection
Dim ha, hb, hc, hd, he, hf, hg, hh, hi, hj As String
Dim i, x As Integer
Dim HTMLInput As MSHTML.IHTMLElement

IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=MCX"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop

Set hdoc = IE.document
Set HTMLInput = hdoc.getElementsByClassName("blkbox-whitetxt").Item

Debug.Print HTMLInput.innerText



End Sub

如果第一次运行没有结果,请尝试第二次运行:

在此处输入图像描述

于 2021-06-04T07:26:40.103 回答