简体   繁体   English

未找到 url 上的 google 表格 importxml 资源 - 雅虎财经

[英]google sheets importxml resource at url not found - Yahoo Finance

I tried to get Walgreen's number of full-time employees from Yahoo Finance using importxml like so:我尝试使用 importxml 从雅虎财经获取 Walgreen 的全职员工人数,如下所示:

=importxml("https://finance.yahoo.com/quote/WBA/profile", "/html/body/div[1]/div/div/div[1]/div/div[3]/div[1]/div/div[1]/div/div/section/div[1]/div/div/p[2]/span[6]/span")

在此处输入图片说明

I have used the function successfully in getting other figures from Yahoo Finance.我已成功使用该功能从雅虎财经获取其他数据。 Example (market cap):示例(市值):

=mid(importxml("https://finance.yahoo.com/quote/WBA", "/html/body/div[1]/div/div/div[1]/div/div[3]/div[1]/div/div[1]/div/div/div/div[2]/div[2]/table/tbody/tr[1]/td[2]/span"),1,6)+0

But with the number of employees (and, by the way, also the trailing twelve months' (ttm) revenues) - I get this error.但是随着员工数量(顺便说一下,还有过去十二个月的(ttm)收入) - 我得到了这个错误。

Without VBA, with which I am not familiar, how can this be fixed?如果没有我不熟悉的 VBA,如何解决这个问题?

Thanks!谢谢!

This site is built client side by javascript, not server side.该站点是由 javascript 构建的客户端,而不是服务器端。 Therefore, native functions are inoperative.因此,本机功能不起作用。

You have to extract the json inside the source and parse it.您必须提取源中的 json 并解析它。

The object is named root.App.main inside the source.该对象在源中被命名为root.App.main

To get employees for instance以获取员工为例

function fullTimeEmployees(url='https://finance.yahoo.com/quote/WBA/profile'){
  var source = UrlFetchApp.fetch(url).getContentText()
  var jsonString = source.match(/root.App.main = ([\s\S\w]+?);\n/)
  if (!jsonString || jsonString.length == 1) return;
  var data = JSON.parse(jsonString[1].trim())
  Logger.log(data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM