Google Sheets – Query to Import HTML/XML Data

google sheetsimporthtmlimportxmlxpath

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?

Best Answer

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.