vba - 将 getElementsByClassname 与多个元素一起使用
问题描述
我正在尝试使用 VBA 宏从网站检索价格。通常,以下代码可以正常工作(示例):
price = html.getElementsByClassName("fpStriked fpStrikedBefore jsStriked").Item(0).innerText
但是,当 HTML 在包含价格的类中有多个属性时,前面的代码无法检索信息。这是包含多个属性的类的示例
"span class="fpPrice price jsMainPrice jsProductPrice hideFromPro" itemprop="price" content="33.99" 33<sup>€99</sup>"
price = html.getElementsByClassName("fpPrice price jsMainPrice jsProductPrice hideFromPro").Item(0).innerText
在这种情况下,如何调整代码以获取价格(33.99)?
解决方案
在上面的代码中,getElementsByClassName 将选择具有所有 3 个 ("fpStriked fpStrikedBefore jsStriked") 类的所有元素,但您的 span 没有这些类可供选择。
推荐阅读
- google-chrome - Chromecast - 页面刷新后如何重新连接到会话?
- rest - 多对多场景中的帐户范围 api 密钥
- azure-active-directory - 有没有办法使用像 Passport 这样的库在 NodeJS 中实现 Azure AD 代表(OBO)流?
- php - 资源不时更改的固定资源链接的上次修改标头?
- php - PhpStorm 中的 Xdebug 不显示局部变量
- python - 使用 OpenCV 检测损坏的形状
- kubernetes - curl: (7) 连接 192.168.99.100 端口 31591 失败:连接被拒绝
- perforce - 使用 p4vc 时跳过差异对话框
- pdf - Acrobat 或任何其他 pdf 查看器都不会打印连接线注释
- bash - 将值从 wc -l 命令保存到变量