【问题标题】:Fetch element using ImportHTML with XPath in Google Sheet在 Google Sheet 中使用 ImportHTML 和 XPath 获取元素
【发布时间】:2021-10-07 13:48:47
【问题描述】:

我正在使用 Google Sheet IMPORTHTML() 从网站中获取文本。 我正在尝试使用 XPath 通过 Google Sheet 中的 IMPORTHTML() 从网站获取元素属性的值。我寻求的属性值是在以下代码部分中找到的内容。

我正在寻找的值是 50 分

 <div class="section">
    <div class="left">
      <div id="search" class="input">
        <span class="select-box">Test Section</span>
        <input type="text" id="txtSymbol" class="select-box">
        <input type="button" id="btnHistory" class="input-button">
      </div>
      <span id="score" class="score">Score 50 </span>
    </div>
  </div>

尝试了多种方式,以下是一些:

  1. //span[@class='score']/@content 我得到#N/A;
  2. //div[@class='search']/span[@class='score']/@content 我得到#N/A;
  3. //div[@class='search']/span[1]/@content 我得到#N/A;

感谢您为完成这项工作提供的少量支持。 谢谢。

【问题讨论】:

  • 元素文本使用text() 函数而不是不存在的@content 属性访问。试试这个//div[@class='search']/following-sibling::span[@id='score']/text()

标签: html google-sheets xpath google-sheets-formula google-finance


【解决方案1】:

如评论中所述,要获取节点文本,您应该使用 @content 而不是 text()
所以这应该有效:

//span[@class='score']/text()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-31
    • 1970-01-01
    • 2020-07-17
    • 2022-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多