Google importXML 函数的 XPath 查询
XPath query for Google importXML function
我正在尝试编写一个 xpath 查询,以使用 importXML 函数从 google 电子表格中的网页导入一些内容。我需要在以下网页的“社区情绪”下捕获购买百分比:
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,我使用 "inspect element" 函数,然后使用 "copy xpath",这给了我以下....
//*[@id="MshareElement"]
但是当我在具有 importxml 功能的 Google 工作表中使用时,这没有得到任何结果。我的编程知识为零,我正在尝试使用此功能学习网络抓取技术。
请帮忙。
尝试:
=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'"), ">(.+?)<")
我正在尝试编写一个 xpath 查询,以使用 importXML 函数从 google 电子表格中的网页导入一些内容。我需要在以下网页的“社区情绪”下捕获购买百分比: 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,我使用 "inspect element" 函数,然后使用 "copy xpath",这给了我以下....
//*[@id="MshareElement"]
但是当我在具有 importxml 功能的 Google 工作表中使用时,这没有得到任何结果。我的编程知识为零,我正在尝试使用此功能学习网络抓取技术。
请帮忙。
尝试:
=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'"), ">(.+?)<")