importXML Parse Error

牧云@^-^@ 提交于 2019-11-27 06:27:34

问题


I need to parse balance sheet data for a given set of stocks on otcmarkets.com. I'm trying to use the importXML function in Google Spreadsheet, but it is not returning any data for me. The xPath query did not return any data. Here is the function I'm using:

=importxml("http://www.otcmarkets.com/stock/AAEH/financials","//*[@id=’totalCurrentLiabilities’]")

Let me know what I'm doing wrong and if there is a better way to parse specific balance sheet data.


回答1:


The page contents are loaded using JavaScript, which is not executed in Google Spreadsheets. You cannot parse this page using =importxml(...).

What to do now?

  • Ask the providers if they offer an API. Most probably they don't want to be scraped anyway.
  • Analyze the page logic and find the JavaScript call which loads the data, and fetch it yourself. Most probably it is in JSON format, which is not easy to parse in Google Spreadsheets without external libraries.
  • Use some environment to query the data which will execute the JavaScript calls, for example Selenium. Will result in much more programming than using Google Spreadsheets.



回答2:


Try using the importdata function:

=IMPORTDATA("http://www.otcmarkets.com/otciq/ajax/EdgarFinancialsController.json?ticker=AAEH&mode=annual")


来源:https://stackoverflow.com/questions/20766174/importxml-parse-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!