Ian Finlay
Ian Finlay

Reputation: 119

Scrape the current share price data from the ASX

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

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

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.

Other xpaths I have tried are:

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

Example: Share price is 0.910

CHrome inspect element

Upvotes: 1

Views: 5317

Answers (1)

Ian Finlay
Ian Finlay

Reputation: 119

Alternate Solution using Apps Scripts (javascript)

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;
}

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

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

EU USA

Upvotes: 3

Related Questions