首页 > 解决方案 > XPath query for importing web content

问题描述

Can anyone please suggest how to import '500112' and 'SBIN' from https://www.moneycontrol.com/india/stockpricequote/banks-public-sector/statebankindia/SBI in Google spreadsheet using importData or importXML functions?

标签: xpathweb-scrapinggoogle-sheetsgoogle-sheets-formulagoogle-sheets-importxml

解决方案


尝试使用

=IMPORTXML(A1,"//ctag[@class='mob-hide']//span") #where A1 is the url

这应该让你们俩都受益。

添加,例如:

=IMPORTXML(A1,"//ctag[@class='mob-hide']//span[1]")

最后应该只输出

500112

编辑:

自从提出问题以来,该站点开始使用 GS 无法处理的动态加载数据。使用浏览器“开发人员”选项卡中的工具,您可以发现目标数据是从不同的站点(见下文)加载的,并且是 json 格式。

所以你需要使用 GS 的importJSON()功能:

A1 = https://priceapi.moneycontrol.com/pricefeed/bse/equitycash/SBI

A2 =importJSON(A1)

确保工作表上有足够的空间来扩展输出。完成后,您将在 和 列下找到两个目标项Data BseidData Nseid可能在 AL 和 AM 列中。


推荐阅读