rvictordelta rvictordelta - 1 year ago 87
Python Question

Scraping with Python Selenium: iterate through html table without tags

I'm a Python neophyte working on a fun little scraping project. Trying to pull info from here:

I'm in Python 2 and using Selenium

There's a table on the page with aircraft details. I want to iterate through the second column of this table, which is labeled "Active". Normally, I would select the table by using

. However, this table doesn't have an
tag. I think I need to find the table by
, but I am unsure of the path syntax to find the table and then also the rows in the second column.

In summary, how can I iterate through the rows of a table if the table does not have any identifying tags?

Answer Source

You could use CSS selector or XPath. As mentioned in the comments, your browser's dev tools probably have a builtin way to do this.

That table's Xpath is


And a CSS selector that you can use is

body > table:nth-child(6) > tbody > tr:nth-child(1) > td > table:nth-child(3) > tbody > tr > td:nth-child(2) > table

In Chrome, for example, you can obtain this information in the following way:

(1) Open up the dev tools and find the element. You can do this by right-clicking any element and clicking "inspect"

enter image description here

2) Right-click the element in the DOM, then select Copy > (Copy Selector / Copy XPathenter image description here