2

I'm a Python neophyte working on a fun little scraping project. Trying to pull info from here: http://www.airfleets.net/flottecie/American%20Airlines.htm

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 find_element_by_id. However, this table doesn't have an id tag. I think I need to find the table by find_element_by_xpath, 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?

1
  • 1
    you can get elements by_tag or by_class. It gives list of elements and you can work like with normal list - using index (lst[x]), for loop (for x in lst), etc. you can event use find_element_by with every element on list to get "subelement". BTW. Chrome and Firefox has DevTools and you can see "xpath" or "css selector" (sometimes you need install extension) Commented Oct 28, 2016 at 19:21

1 Answer 1

4

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

/html/body/table[4]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table 

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.