Skip to content
Advertisement

How to find the attribute and element id by selenium.webdriver?

I am learning web scrapping since I need it for my work. I wrote the following code:

JavaScript

However, it is showing the following error:

JavaScript

Then I inspect the table that I wanna scrape this table from this page enter image description here

what is the attribute that needs to be included in get_attribute() function in the following line?

JavaScript

what I should write in the driver.find_element_by_id?

EDITED: Some tables have lots of records in multi-pages. For example, this page has 2,246 entries, which shows 100 entries on each page. Once I tried to web-scrape it, there were only 320 entries in df and the record ID is from 1232-1713, which means it took entries from the next few pages and it is not starting from the first page to the end at the last page.

What we can do in such cases?

Advertisement

Answer

You need to get the outerHTML property of the table first, then call the table element from pandas.

You need to wait for element to be visible. Use explicit wait like WebdriverWait()

JavaScript

Import below libraries.

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement