简体   繁体   English

如何从 Google Finance(或 yahoo finance)获取财务数据到 Google 表格中?

[英]How can you get financial data from Google Finance (or yahoo finance) into Google Sheets?

I'm struggling to get financial data into google sheets.我正在努力将财务数据输入谷歌表格。 I read some answers here and tried this: =importhtml("https://www.google.com/finance?q="&B2&"&fstype=ii&ei=viASWOnfNsfEeqqUnMgG","table",3)我在这里阅读了一些答案并尝试了这个: =importhtml("https://www.google.com/finance?q="&B2&"&fstype=ii&ei=viASWOnfNsfEeqqUnMgG","table",3)

Yet it always shows this error:但它总是显示此错误:

Imported content does not have query with given index.导入的内容没有给定索引的查询。

I went through the tables from 2-10 but nothing worked.我浏览了 2-10 的表格,但没有任何效果。 It would be great if someone can help me with this.如果有人可以帮助我,那就太好了。 If you only know how to get data from yahoo finance or some other stock website then it would be nice if you'd also say that.如果您只知道如何从雅虎财经或其他一些股票网站获取数据,那么如果您也这么说就好了。 I tried yahoo finance but there it always says:我试过雅虎财经,但它总是说:

URL could not be fetched无法获取 URL

or something like that.或类似的东西。

For google, there is a formula googlefinance.对于 google,有一个公式 googlefinance。 For yahoo, all datas are imported in the code source within a big json you can fetch by this way对于雅虎,所有数据都导入到大 json 中的代码源中,您可以通过这种方式获取

  var source = UrlFetchApp.fetch(url).getContentText()
  var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
  var data = JSON.parse(jsonString) 

you can then navigate through data to retrieve the informations you need.然后,您可以浏览数据以检索您需要的信息。

See formula GOOGLEFINANCE in Google Sheets.请参阅 Google 表格中的公式 GOOGLEFINANCE。 It's not totally live (about 20 minutes delay) but for many purposes is enough.它不是完全实时的(大约延迟 20 分钟),但对于许多目的来说就足够了。 I use it mostly for currency exchange rates but there far more options:我主要将它用于货币汇率,但还有更多选择:

https://support.google.com/docs/answer/3093281?hl=en https://support.google.com/docs/answer/3093281?hl=en

Yahoo Finance and most of live sites are protected against webscraping or use javascript (that makes parts generated by javascript impossible for import by formulasa like IMPORTHML, IMPORTXML, IMPORTDATA).雅虎财经和大多数实时网站都受到保护,防止网页抓取或使用 javascript(这使得 javascript 生成的部分无法通过 IMPORTHML、IMPORTXML、IMPORTDATA 等公式导入)。

I also built a Google sheets add-on that allows you to access fundamental and realtime financial data for tens of thousands of global companies, ETFs and Cryptos.我还构建了一个 Google 表格插件,允许您访问数以万计的全球公司、ETF 和 Cryptos 的基本和实时财务数据。 You can access fundamental information like revenue or cashflow from specific years.您可以访问特定年份的收入或现金流等基本信息。 It's still in its early phases but you can check it out in the add-on store, it's called SheetsFinance (sheetsfinance.com)它仍处于早期阶段,但您可以在名为 SheetsFinance (sheetsfinance.com) 的附加商店中查看它

Feel free to drop me a line and ask any more questions about it请随时给我留言并询问更多有关它的问题

Regarding cryptocurrency coins you can simply use关于加密货币硬币,您可以简单地使用

=IMPORTDATA("https://cryptoprices.cc/BTC/")

Google Finance only supports the very biggest coins (BTC, ETH), not much more. Google 财经仅支持最大的代币(BTC、ETH),仅此而已。

Other services usually require fragile web page parsing which is difficult, error prone and not a long term solution.其他服务通常需要脆弱的 web 页面解析,这很困难,容易出错并且不是长期解决方案。

From looking at some of your comments, you may be looking at something more complex and get a lot more data together.通过查看您的一些评论,您可能正在查看更复杂的内容并获得更多数据。 That will probably require access to paid services and some software programming to get it working together.这可能需要访问付费服务和一些软件编程才能使其协同工作。

Google Sheets is not a scraping software, it can pull data from websites and do some limited parsing, but most websites protect against it and or may change over time.谷歌表格不是一个抓取软件,它可以从网站中提取数据并进行一些有限的解析,但大多数网站都可以防止它,或者可能会随着时间的推移而改变。 Trying to do what you want to do may be the best way to do it.尝试做你想做的事可能是最好的方法。

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

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