importXML xPath:从网站检索股票信息到Google表格 [英] importXML xPath: Retrieve stock information from website to Google Sheets

查看:182
本文介绍了importXML xPath:从网站检索股票信息到Google表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过Google表格从本网站检索EPS股票信息?




How can I retrieve the EPS stock information from this website via Google Sheets? http://seekingalpha.com/symbol/KO

What I would like to output in Google Sheets is this value:

1.66

On the site I believe that the relevant XML Code to pull that information from is this:

<span class="right" id="qp_eps">1.66</span>

This Google Sheet formula does not return anything than an error:

=ImportXML("http://seekingalpha.com/symbol/KO/focus", "//span[@id='qp_eps'")

解决方案

I Have a workaround for you:

Using IMPORTDATA instead of IMPORTXML, you can use Index which oddly, even with different tickers, is quite consistent:

There are two ways to go about it - First is using Index twice:

=INDEX(SORT(INDEX(IMPORTDATA("http://seekingalpha.com/symbol/KO"),,55)),3)

And if you want to clean it up to only return the value you can substitute the "eps:" portion:

=SUBSTITUTE(INDEX(SORT(INDEX(IMPORTDATA("http://seekingalpha.com/symbol/KO"),,55)),3),"eps:","")

Second is to use index again but instead of Indexing twice, you can just join the values and regex out what you want:

=REGEXEXTRACT(CONCATENATE(SORT(INDEX(IMPORTDATA("http://seekingalpha.com/symbol/AAPL"),,55))),"eps:(.*)NOW_P")

Here are two screenshot of the two types:

这篇关于importXML xPath:从网站检索股票信息到Google表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆