0

I'm using Google Spreadsheets to retrieve a data table ('id=idp6855942304') from this site. The full sets of tables can be viewed by clicking on "All Reports" from the menus on the left side of the page. URL in formulas below refer to the site. The page has an HTML DOCTYPE.

Using =IMPORTHTML(URL,"table",1) returns an outline listing of all the tables' titles in a cell and not their contents. Any other index number except zero returns an error, "Imported content does not have query with given index."

Using =IMPORTXML(URL,"(//body/div/table)[position() = 1]") also returns a listing of all tables. I've also tried using as the query:

//table[class='report']//id[contains(.,'idp6855942304')]/tbody

and

//table[class='report']//@id='idp6855942304'

The former returns an empty content error and the latter returns FALSE.

What is the XPath query to select the second table ("idp6855942304") on the page?

  • Looking to the source of the web page, there isn't a tbody tag. If you found it using the developer tools of your browser it's very likely that it was added by the browser itself or a browser extension. I didn't found "idp6855942304" on the webpage maybe because it's loaded only after the user clic on "All reports" – Rubén May 31 '16 at 22:08
  • It may have been Chrome and FF adding the tbody tag. Yes, the page source doesn't seem to capture all displayed. Could you recommend another inspector to review the page and I'll revise? – Catalyx May 31 '16 at 22:20
  • Yes, it appears that the page's source has an array that loads the tables. I'll revise the question and point to the XML file. – Catalyx May 31 '16 at 23:03
  • Google Sheets functions like IMPORTHTML and IMPORTXML only will get the default content from the source page. Regarding another inspector, looks that you already found what is needed in the case of the referred web page. – Rubén Jun 1 '16 at 0:18
  • @Rubén Yes, the page's source has the target webpage for each report. I found it and applied IMPORTHTML. This should reduce the load on Google's service and prevent timeouts. Thanks. – Catalyx Jun 1 '16 at 3:34
0

The referred site use JavaScript to load several tables from other files after the user click on the "All Reports" link.

The solution is to find the source file of the desired table and use its URL instead of the one considered in first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.