【问题标题】:XPath query for Google importXML functionGoogle importXML 函数的 XPath 查询
【发布时间】:2020-05-06 20:33:41
【问题描述】:

我正在尝试编写一个 xpath 查询,以使用 importXML 函数从谷歌电子表格中的网页导入一些内容。我需要在以下网页上的 COMMUNITY SENTIMENTS 下获取购买百分比: https://www.moneycontrol.com/india/stockpricequote/banks-public-sector/statebankindia/SBI

此百分比在发布此消息时显示为 73%,但以后可能会更改。 (所以我需要在我的 Google 表格中导入 73%)。

该页面的相关HTML代码有以下脚本:

</script>
        <ul class="buy_sellper">
            <li><span result="73" class="bullet_clr buy buy_results"></span>73% BUY</a></li>
            <li><span result="20" class="bullet_clr sell sell_results"></span>20% SELL</a></li>
            <li><span result="7" class="bullet_clr hold hold_results"></span>7% HOLD</a></li>
        </ul>
                    </div>
                </div>
                <div class="chart_fr ">

            <div class="txt_pernbd">73%</div>
            <div class="cht_mt25">of moneycontrol users recommend <span class=green_txt>buying</span> SBI</div>
                </div>
            <!-- buy, sell, hold starts -->
<div class="buy-sell-hold">
    <p>What's your call on SBI today?</p>
    <p>

使用 Chrome,我使用了“检查元素”功能,然后使用了“复制 xpath”,这给了我以下内容......

//*[@id="MshareElement"]

但是当我在 Google 表格中使用 importxml 功能时,这并没有得到任何结果。我的编程知识为零,我正在尝试使用此功能学习网络抓取技术。

请帮忙。

【问题讨论】:

  • 尊敬的@Player0,非常感谢您的回复。 我花了这么多时间来理解importxml的语法,但仍然没有得到解决方案。而且我从没想过答案会存在于多个功能之间。非常感谢您的支持。
  • 嗨@player0,您能否建议如何从[链接] (moneycontrol.com/india/stockpricequote/banks-public-sector/…) 在 Google 电子表格中导入“500112”和“SBIN”。另外,请建议我如何学习编写这样的 xpath 查询。

标签: xpath web-scraping google-sheets google-sheets-formula google-sheets-importxml


【解决方案1】:

尝试:

=REGEXEXTRACT(QUERY(IMPORTDATA(
 "https://www.moneycontrol.com/india/stockpricequote/banks-public-sector/statebankindia/SBI"), 
 "where lower(Col1) contains 'txt_pernbd'"), ">(.+?)<")


=REGEXEXTRACT(QUERY(IMPORTDATA(
 "https://www.moneycontrol.com/india/stockpricequote/banks-public-sector/statebankindia/SBI"), 
 "where lower(Col1) contains 'bullet_clr sell sell_results'"), "/span>(.+?)</a")


=REGEXEXTRACT(QUERY(IMPORTDATA(
 "https://www.moneycontrol.com/india/stockpricequote/banks-public-sector/statebankindia/SBI"), 
 "where lower(Col1) contains 'investor views'"), ">(.+?)<")

【讨论】:

  • 您能否建议如何提取卖出百分比以及提取该百分比所基于的投资者数量(均在社区情绪部分给出)。我知道我可能要求太多,但会非常感谢您的帮助!:)
  • 嗨@player0,您能否建议如何使用importXML 函数/ xpath 查询在Google 电子表格中导入“500112”和“SBIN”? (moneycontrol.com/india/stockpricequote/banks-public-sector/…)
  • 嗨@player0,感谢您的帮助。谢谢。
猜你喜欢
  • 1970-01-01
  • 2015-05-09
  • 2018-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多