【发布时间】:2014-12-23 15:12:03
【问题描述】:
我很难从名为 points 的输入中检索值 300。
这是我的 HTML 和 VBA 代码。
HTML:
<td id="myPower_val_9" style="visibility: visible;">
<input type="text" disabled="disabled" value="300" name="points"></input>
</td>
VBA:
Dim ie As Object
Dim myPoints As String
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = 0
.navigate "www.example.com"
While .Busy Or .readyState <> 4
DoEvents
Wend
End With
Dim Doc As HTMLDocument
Set Doc = ie.document
myPoints = Trim(Doc.getElementsByTagName("td")(0).getElementById("myPoints").innerText)
Range("A1").Value = myPoints
【问题讨论】:
-
你为什么希望它起作用?
-
我的工作场所也有类似的html代码。我需要从输入类型中检索值,但我尝试了很多次都没有成功。
-
innerText 将为您提供标签之间的内容;那不是你想要的。您想要“值”属性的值。
-
你是说如果我把“innerText”改成“value”就能解决问题?
-
您可能需要将其更改为
.getAttribute("value")或类似的名称。
标签: html vba excel web-scraping