从ASX抓取当前股价数据 [英] Scrape the current share price data from the ASX

查看:52
本文介绍了从ASX抓取当前股价数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将来自ASX的当前股价数据抓取到Google电子表格中.

I am trying to scrape the current share price data from the ASX into a Google spreadsheet.

我不使用 = googlefinance("ASX.NEA","price")进行瞬时延迟价格,因为该决议会四舍五入为便士股票的价值.

I am NOT using =googlefinance("ASX.NEA","price") for instantanious delayed price as the resolution rounds the value for penny stocks.

我未将 = INDEX(googlefinance("ASX.NEA",价格",today()-10,today()),2,2)用于历史价格即使分辨率价格准确,也无法获得当前日期价格.

I am NOT using =INDEX(googlefinance("ASX.NEA","price", today()-10, today()),2,2) for historical prices this can not get the current days price even though resolution price is accurate.

  • URL: https://www.asx.com.au/asx/share-price-research/company/NEA

xpath(xPath Finder):/html/body/section [3]/article/div [1]/div/div/div [4]/div [1]/div [1]/company-summary/table/tbody/tr [1]/td [1]/span

xpath (xPath Finder): /html/body/section[3]/article/div[1]/div/div/div[4]/div[1]/div[1]/company-summary/table/tbody/tr[1]/td[1]/span

等式: = IMPORTXML(url,xpath)

结果:#N/A错误导入的内容为空

result: #N/A Error imported content is empty

我尝试过的其他xpath是:

Other xpaths I have tried are:

  • xpath://table/tbody//span
  • xpath://span [@ ng-show ="share.last_price"]
  • xpath://span [@ ng-show ="share.last_price"]

当我查看页面源代码时,将通过javascript加载最新股价.

When I view page source, the latest share price is loaded via javascript.

示例:股价为0.910

Example: Share price is 0.910

推荐答案

使用应用脚本的替代解决方案(javascript)

Alternate Solution using App Scripts (javascript)

<code>
    function AsxPrice(asx_stock) {
      var url = "https://www.asx.com.au/asx/1/share/" + asx_stock +"/";
      var response = UrlFetchApp.fetch(url);
      var content = response.getContentText();
      Logger.log(content);
      var json = JSON.parse(content);
      var last_price = json["last_price"]; 
      return last_price;
    }
</code>

当HTML膨胀时,这比importXML()或ImportHTML()效率要高得多,上述网址是jsonresult.

This is far more efficient that importXML() or ImportHTML() as HTML is bloated, the above url is a jsonresult.

对于其他大型证券交易所(可在以下位置找到json来源):

For other large stock exchanges (json source can be found at) :

欧盟美国

这篇关于从ASX抓取当前股价数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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