我正在尝试从页面获取数据,但我收到错误"对象不支持此属性或方法"当我想获得冠军时
页面来源是
<div class="title">
<span title="Naviforce Men's Black Dial Leather Band Watch - NF9055-BKRD">Naviforce Men's Black Dial Leather Band Watch - NF9055-BKRD</span>
</div>
我的vba代码是
title = Trim(Doc.getElementsByClass("title").innerText)
ActiveCell.Offset(0, 1).Value = title
我添加了两个引用&#34; microsoft HTML对象库&#34;和#34;微软互联网控制&#34;
提前致谢
答案 0 :(得分:2)
该函数的名称为getElementsByClass
,表示您获得&#34;元素&#34; (plurial)。你的错误是&#34; innerText&#34;在此列表容器中不存在。
您必须获取列表的第一个元素才能检索DOM元素
title = Trim(Doc.getElementsByClass("title")(1).innerText)