1

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.

  • 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

  • equation: =IMPORTXML(url, xpath)

  • result: #N/A Error imported content is empty

Other xpaths I have tried are:

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

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

Example: Share price is 0.910

CHrome inspect element

Rubén
  • 34,714
  • 9
  • 70
  • 166
Ian Finlay
  • 121
  • 2
  • 9

1 Answers1

3

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

Rubén
  • 34,714
  • 9
  • 70
  • 166
Ian Finlay
  • 121
  • 2
  • 9
  • Handy workaround now that GoogleFinance calls appear to be broken for US domiciled funds (like VTS/VEU) (since Tuesday 21-Jan-2020) – ZENNON Jan 23 '20 at 01:24
  • In one case in order to avoid the "Unexpected token < in JSON at position 0" I had to use var json = JSON.parse(JSON.stringify(content)) because the response was HTML instead of JSON. – rearThing Mar 25 '20 at 17:23