【问题标题】:VBA extract value from html tableVBA从html表中提取值
【发布时间】:2017-12-11 22:02:39
【问题描述】:

我想废弃以下 html 代码以从“resultsTable”的“td”标签之一中提取值

enter image description here

我尝试在下面运行 vba 代码,但它不起作用。我收到了

运行时错误代码“91”

Dim appIE As Object
Set appIE = CreateObject("internetexplorer.application")

With appIE
.navigate "https://www.investing.com/stock-screener/?
 sp=country::5|sector::a|industry::a|equityType::a|exchange::a%3Ceq_market_cap;1"
.Visible = True
End With

Do While appIE.Busy
DoEvents
Loop

Set table = appIE.document.getElementById("resultsContainer").Children(1)

Set tbody = table.getElementsByTagName("tbody")(0)

trs = tbody.getElementsByTagName("tr")

Dim myvalue As String: myvalue = trs.Cells(3).innerText
appIE.Quit
Set appIE = Nothing

MsgBox myvalue

【问题讨论】:

  • 哪一行导致错误?
  • 嗨,安迪,这行代码是“将 myvalue 作为字符串调暗:myvalue = trs.Cells(3).innerText”

标签: html vba excel


【解决方案1】:

您不允许页面加载时间。等待.Busy 完成并不意味着页面已加载且页面元素可用。

这是暂停某些相关内容可用的一种方法:

trs = tbody.getElementsByTagName("tr")

Do While trs Is Nothing
    DoEvents
    Application.Wait Now + TimeValue("00:00:02")
    trs = tbody.getElementsByTagName("tr")
Loop

【讨论】:

  • 太棒了!现在代码运行良好。非常感谢您的支持!
猜你喜欢
  • 2021-01-05
  • 2017-06-02
  • 1970-01-01
  • 2016-11-23
  • 2019-11-20
  • 1970-01-01
  • 1970-01-01
  • 2016-10-13
  • 1970-01-01
相关资源
最近更新 更多