Reputation: 119
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:
//table/tbody//span
//span[@ng-show="share.last_price"]
//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
Upvotes: 1
Views: 5317
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