Google-sheets – Extract table from moneycontrol.com

google sheetsimporthtmlimportxml

I'm trying to extract data from a table into Google Sheets, from this webpage:
http://www.moneycontrol.com/stocks/fno/marketstats/futures/gainers/homebody.php?opttopic=&optinst=allfut&sel_mth=1&sort_order=0

I've tried using "IMPORTHTML" and "IMPORTXML" both, however, they do not seem to work. Any suggestions would be greatly appreciated!

This is the error message that comes up on running both the queries:

Error
Imported content is empty.

FYI this is what I typed into the spreadsheet:

=IMPORTHTML(" http://www.moneycontrol.com/stocks/fno/marketstats/futures/gainers/homebody.php?opttopic=&optinst=allfut&sel_mth=1&sort_order=0
", "TABLE", 2)

The table is not dynamically created as it is available in the page source. Even changing the index of the IMPORTHTML function does not help. every index returns "Imported content is empty".

Best Answer

When URL: http(s)://www.moneycontrol.com/stocks/fno/marketstats/futures/gainers/homebody.php?opttopic=&optinst=allfut&sel_mth=1&sort_order=0

opened in client (browser) following server side rendering of dynamic data are requested by browser:

 - send @   jquery-1.12.0.min.js:4 
 - ajax @   jquery-1.12.0.min.js:4
 - updaterss    @   jquery.webticker.js:39
 - (anonymous)  @   jquery.webticker.js:137
 - many more...

this is why you can not use IMPORTHTML or IMPORTXML to fetch Dynamic data as in this webpage.

How to check if Error: Imported Content is Empty is because of dynamic data?

  1. use a la carte rendering of web page in question like:

    =IMPORTXML("http://www.moneycontrol.com/stocks/fno/marketstats/futures/gainers/homebody.php?opttopic=&optinst=allfut&sel_mth=1&sort_order=0", "/")

    • "/" will force to fetch everything from URL, and there is nothing useful in this IMPORT XML/HTML for your need.
  2. Using the Chrome browser's INSPECT function displays all the client requests.