I'm trying to fetch a piece of data using importxml()
but it just fails with "Loading…" and never resolves. Other pages have no such problem at all, just this one and I don't know why.
Here is the formula that doesn't work:
=ImportXML("http://eoddata.com/stockquote/OPRA/WFM160826P00032000.htm", "//*[@id='ctl00_cph1_qp1_div1']/div[2]/table/tbody/tr[2]/td[5]/font/b")
Ultimately I'm trying to fetch the "bid", "ask", and "open interest" elements, but all fail. By way of comparison, this works fine:
=ImportXML("http://finance.yahoo.com/quote/WFM160826P00032000", "//*[@id='quote-summary']/div[1]/table/tbody/tr[4]/td[2]")
any ideas what's wrong?
Best Answer
Short answer
The problem is the xPath, specifically the
/tbody
part as it's not present in the source code.Explanation
The source html code of the page doesn't include the tbody tag. It's added by the browser when it is missed to create a DOM hierarchy but the algorithm behind IMPORTXML doesn't do the same, it requires the xPath for the original source code of the web page.
Removing it from the xPath will solve the problem.
The following formula returns the value of OPEN INT,
141
:References
https://stackoverflow.com/questions/938083/why-do-browsers-insert-tbody-element-into-table-elements