The Simple Way to Scrape an HTML Table: Google Docs

Raw data is the best data, but a lot of public data can still only be found in tables rather than as directly machine-readable files. One example is the FDIC’s List of Failed Banks. Here is a simple trick to scrape such data from a website: Use Google Docs.

The table on that page is even relatively nice because it includes some JavaScript to sort it. But a large table with close to 200 entries is still not exactly the best way to analyze that data.

After some digging around – and even considering writing my own throw-away extraction script –, I remembered having read something about Google Docs being able to import tables from websites. And indeed, it has a very useful function called ImportHtml that will scrape a table from a page.

To extract a table, create a new spreadsheet and enter the following expression in the top left cell:

=ImportHtml(URL, "table", num)

URL here is the URL of the page (between quotation marks), “table” is the element to look for (Google Docs can also import lists), and num is the number of the element, in case there are more on the same page (which is rather common for tables). The latter supposedly starts at 1, but I had to use 0 to get it to pick up the correct table on the FDIC page.

Once this is done, Google Docs retrieves the data and inserts it into the spreadsheet, including the headers. The last step is to download the spreadsheet as a CSV file.

This is very simple and quick, and a much better idea than writing a custom script. Of course, the real solution would be to offer all data as a CSV file in addition to the table to begin with. But until that happens, we will need tools like this to get the data into a format that is actually useful.

Published by

Robert Kosara

Robert Kosara is a Research Scientist at Tableau Software, and formerly Associate Professor of Computer Science. His research focus is the communication of data using visualization. In addition to blogging, Robert also runs and tweets.

45 thoughts on “The Simple Way to Scrape an HTML Table: Google Docs”

  1. It took under a minute to set up a web query in Excel to extract the data. Data menu > Import External Data > New Web Query. Enter the URL, then select the table you want imported. Whenever you want, you can click on the imported table. The External Data toolbar pops up, and you can click on the icon with the exclamation point to update the query. It’s a simple matter to save the sheet with the data as a CSV.


    This is a very nice trick. For more complex data extraction needs, I’ve been playing with Open Dapper ( and I found it quite powerful: it’s able to extract data from almost any page showing any kind of regularity – not just tables – and export it at least as csv or rss (and you can access the rss from an url which stays live, updating the feed as the original page update etc.)

    (I’ve searched the site for “Dapper” and the search engine returns no results, so I thought it could be useful to point it to you – thanks for this blog and for your work!)

  3. That’s probably where I saw this. I actually did this a while ago and couldn’t find the page where I had seen the ImportHtml trick when I wrote the posting. I’ll add a link.

    1. Tabula ( http://tabula.Technology/ ) may work for you. I haven’t had too much time to play around with it yet, but it shows some promise. The PDF would need to be OCR’d first, and they say it still struggles with headers. But if you have a really dense table that needs scraped, I’m sure there are worse things out there.

  4. The good thing about HTML is that tables are very clearly structured in the markup. That’s not the case in PDF, where it’s just stuff that happens to line up and maybe lines that are drawn in-between. Best option is probably to copy&paste from the PDF into Excel or another spreadsheet app.

  5. Let’s combine your climate data and web scrapping posts.

    Here’s an example where I scrapped climate science data for a visualization of the IR absorption properties of 5 greenhouse gases.


    I wanted to scrap the spectrum data from 5 NIST Chemistry Webbook data web pages and generate this chart automatically.

    Jon Peltier is right about Excel’s external data capabilities, however, Jon would need a VBA procedure to retreive the data and reproduce my 5 panel chart.

    Bill Dedman’s suggestion about using Excel’s cut and paste approach would be quite time consuming and Bill would have a challenge generating the 5 panel chart.

    Here’s a link to my post, it includes a link to my R script, available on Google docs.



  6. This is a great website, but you have some syntax errors:

    =ImportHtml(URL, “table”, num)

    should be:
    =ImportHtml(URL; “table”; num)

  7. You could have used MS Excel’s “Data–>From Web” option to fetch tables from web sites. It’s more easy and workable. And it could be updated automatically also when spreadsheet opens every time. Cheers…

  8. i’m a newbie with complex ideas and no programming skills. i need to extract table data from an internal web portal page. i can’t find the table id. i’m in firefox and viewed the frame source. all i can find is a table class. thoughts? ideas? if i can make this work, i’ve just saved myself hours per week.

  9. Another good way to import data into a spreadsheet is from JSON data. If you use you can upload text or enter a URL and a spreadsheet will be produced.

  10. Thanks definitely useful – I didn’t know Google docs had this feature.
    I approached this issue however differently making my own Add-In and UDF functions so that there would be no need of writing VBA as in the Google example:

    Gettting a href is easy:

    A more elaborate example as yours above, of getting the tables contents in Excel, is also not that complicated and just requires nesting of the UDF:

    gets the first cell contents of the first row and the first table. Changing the “0” to higher numbers will get the next rows, cells etc. so the formulas can be dragged like other excel formulas :).

    Hope this will interest you!

    1. No, because the table on that page is just raw text, not HTML. I don’t know if something like would work, but worth a try. You’d need to extract the text table and then run that through something that can parse tab-separated data, like Google Refine or Data Wrangler.

      1. Not on import, but once the data is imported, you can sort, filter, etc. in Google Docs. Click a column header to highlight it, then pick Data->Filter from the menu. When you then click on the first row in that column, you get a dropdown that lets you filter, etc.

  11. The page I want to scrape has a submit button on it. Is there a way to get the form to submit and use this method? The default form information is all I need from the table.

  12. Robert,
    This is a great resource, thank you. I’ve been trying to grab the table data from this website:

    The Googlesheets function
    returns the #N/A “imported content is empty” error, as does changing the index to 1, or 2, etc.

    I thought I might be able to use the importXML function, and the HTML from the site i’m attempting to retrieve data from shows:

    Valuation Index – Institutional

    Index Value
    Standard Error

    Oct 1989

    And so on.

    I included the start of the data I want from the first row for Oct 1989. Since the table doesn’t appear to have an id, I’ve tried are “//table/”, “//td”, “//td/”, “//div/” and can’t get the function to return anything so it appears I’m missing some fundamental concept. This can’t be that hard. Do you have any suggestions?

  13. I have read all the posts and tried a variety of approaches but I am not able to extract the data I am looking for with these methods. The website appears to not have a table or list behind the data so that may be the problem – I am not sure. I am looking to extract all of the camps listed in the New England states (CT, ME, MA, NH, RI, VT) from this site: Using the excel approach returns no data (after I select the table created after the search). Google sheets just returns the text on the screen from either a table (0 – 4) or list.

    Any other suggestions please?

  14. I captured the first table OK. How do I automatically capture the next 50 pagination sheets?

    Thanks for this article.

  15. Brilliant one ! Thank you :)

    I improvised a little on it. My challenge was to have information extracted from multiple urls present on one url.

    So with the help of data miner I got all urls extracted on one google spreadsheet, then using importhtml, instead of url, I gave cell address where urls are present to fetch data.

    This has worked well for me.

    Only challenge is the field of email id coming as protected whereas I can see email id mentioned on webpage. This is something still not resolved. Any view?

Leave a Reply