Did you know you can import data tables from any web page to Excel?

I am 31 years old and I didn’t knew this. Everytime I wanted to scrape some data table from a website I had to run a script to do it for me, when in fact it was so easy… like a walk in a park.

Let’s have a brief example of what I mean. So how do you…


This content originally appeared on DEV Community and was authored by George Tudor

I am 31 years old and I didn't knew this. Everytime I wanted to scrape some data table from a website I had to run a script to do it for me, when in fact it was so easy... like a walk in a park.

Let's have a brief example of what I mean. So how do you go from this...

wikipedia page

to this...

parsed page in excel

... in less than 10 seconds.

All you need is the page you want to get the data from, in my case it's this one, and the Excel app opened (you can use Google drive as well).

We will use the IMPORTXML function which takes as parameters an url, an xpath_query and a locale. All we need is to pass the url and the xpath_query of the table.

Our single line of code will look like this:

=IMPORTXML("https://en.wikipedia.org/wiki/List_of_U.S._states_and_territories_by_population", "//tr")

excel formula

So basically we are telling the program to fetch any table row from the page and display it in our sheet. Easy, right?

Remember that you can modify the xpath_query to fetch anything from the page. For example, if I want to fetch the 22nd row of the table I change the function like this:

=IMPORTXML("https://en.wikipedia.org/wiki/List_of_U.S._states_and_territories_by_population", "//table[1]/tbody/tr[24]")

Isn't it awesome? I bet it is. Hope you've learned something! :)


This content originally appeared on DEV Community and was authored by George Tudor


Print Share Comment Cite Upload Translate Updates
APA

George Tudor | Sciencx (2022-02-08T22:35:49+00:00) Did you know you can import data tables from any web page to Excel?. Retrieved from https://www.scien.cx/2022/02/08/did-you-know-you-can-import-data-tables-from-any-web-page-to-excel/

MLA
" » Did you know you can import data tables from any web page to Excel?." George Tudor | Sciencx - Tuesday February 8, 2022, https://www.scien.cx/2022/02/08/did-you-know-you-can-import-data-tables-from-any-web-page-to-excel/
HARVARD
George Tudor | Sciencx Tuesday February 8, 2022 » Did you know you can import data tables from any web page to Excel?., viewed ,<https://www.scien.cx/2022/02/08/did-you-know-you-can-import-data-tables-from-any-web-page-to-excel/>
VANCOUVER
George Tudor | Sciencx - » Did you know you can import data tables from any web page to Excel?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/08/did-you-know-you-can-import-data-tables-from-any-web-page-to-excel/
CHICAGO
" » Did you know you can import data tables from any web page to Excel?." George Tudor | Sciencx - Accessed . https://www.scien.cx/2022/02/08/did-you-know-you-can-import-data-tables-from-any-web-page-to-excel/
IEEE
" » Did you know you can import data tables from any web page to Excel?." George Tudor | Sciencx [Online]. Available: https://www.scien.cx/2022/02/08/did-you-know-you-can-import-data-tables-from-any-web-page-to-excel/. [Accessed: ]
rf:citation
» Did you know you can import data tables from any web page to Excel? | George Tudor | Sciencx | https://www.scien.cx/2022/02/08/did-you-know-you-can-import-data-tables-from-any-web-page-to-excel/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.