Selenium with Python codes for Scraping Table

rifkan(65)
Published in
#curie
Words
157
Reading
1 min
7y
Listen to this post
~1 min

We all need datas. Now think how nice it would be if you can have datas in Tabular format and you can scrape it and can reuse it. Well, friends selenium makes is possible. You can do the same thing with beautifulsoup but the way is a bit more complicated. Here are the codes I wrote for scraping a table from wikipedia about tesla Inc.
For example, bellow is the table I want to scrape.

Screenshot from 2020-03-29 05-58-51.png

Now lets write some code using selenium and python.

Screenshot from 2020-03-29 05-43-36.png

First you import the necessary imports. Then define the driver.

Automate to the website by using driver.get("url") command. Find a elements in the row by using the driver.find_elements_by_xpath and the same for column as well. Use the for loop for getting all the elements in the table and get it in tabular form and print it in the end. Now the result after pushing the code.

Screenshot from 2020-03-29 05-57-14.png

Here you go. Have a nice day.

Selenium with Python codes for Scraping Table | Ecency