Xpath 从澳大利亚证券交易所获取当前股价数据
我正试图将ASX当前的股价数据拼凑成谷歌电子表格 我没有使用Xpath 从澳大利亚证券交易所获取当前股价数据,xpath,web-scraping,google-sheets,google-sheets-importxml,Xpath,Web Scraping,Google Sheets,Google Sheets Importxml,我正试图将ASX当前的股价数据拼凑成谷歌电子表格 我没有使用=googlefinance(“ASX.NEA”,“price”)来计算即时延迟价格,因为决议会对低价股的价值进行四舍五入 我没有使用=指数(googlefinance(“ASX.NEA”,“price”,today()-10,today()),2,2)作为历史价格,即使解析价格准确,也无法获得当前价格 url:https://www.asx.com.au/asx/share-price-research/company/NEA x
=googlefinance(“ASX.NEA”,“price”)
来计算即时延迟价格,因为决议会对低价股的价值进行四舍五入
我没有使用=指数(googlefinance(“ASX.NEA”,“price”,today()-10,today()),2,2)
作为历史价格,即使解析价格准确,也无法获得当前价格
- url:
https://www.asx.com.au/asx/share-price-research/company/NEA
- xpath(xpath查找器):
/html/body/section[3]/article/div[1]/div/div[4]/div[1]/div[1]/company summary/table/tbody/tr[1]/td[1]/span
- 等式:
=IMPORTXML(url,xpath)
- 结果:#不适用错误导入的内容为空
- xpath:
//表/tbody//span
- xpath:
//span[@ng show=“share.last_price”]
- xpath:
//span[@ng show=“share.last_price”]
使用应用程序脚本(javascript)的替代解决方案 这比importXML()或ImportHTML()要有效得多。由于HTML过于膨胀,上面的url是jsonresult 对于其他大型证券交易所(json源代码可在以下网址找到): 欧盟
美国方便的解决办法现在谷歌金融对美国注册基金(如VTS/VEU)的呼叫似乎中断了(从2020年1月21日星期二开始),为了避免“位置0的JSON中出现意外标记”,我不得不使用var JSON=JSON.parse(JSON.stringify(content)),因为响应是HTML而不是JSON。
<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>