There is a root element tbody

In this element there are tr, it is necessary to find tr, which have any id.

How to do this using a CSS selector or XPath. The absence of a class, for example, I know how to do it, but what about the presence of an id?

Markup example:

<tr id="cpu1422" role="row" class="tablesorter-hasChildRow odd" style="display: table-row;">....</tr> <tr class="tablesorter-childRow odd" role="row">...</tr> <tr id="cpu1423" role="row" class="tablesorter-hasChildRow even" style="display: table-row;">...</tr> <tr class="tablesorter-childRow even" role="row">...</tr> <tr id="cpu1490" role="row" class="tablesorter-hasChildRow odd" style="display: table-row;">....</tr> <tr class="tablesorter-childRow odd" role="row">...</tr> <tr id="cpu1769" role="row" class="tablesorter-hasChildRow even" style="display: table-row;">...</tr> 

They can be found either to take only odd order, or by style (I myself can do this). But I would like to try on id

  • Try using BeautifulSoup . - Wiktor Stribiżew
  • @ WiktorStribiżew I use Selenium - danilshik
  • one
    So add this information to the question along with code that does not work. - Wiktor Stribiżew 2:57
  • @ WiktorStribiżew what's the difference, what am I writing on, XPath and css-selectors do not depend on it - danilshik
  • @ WiktorStribiżew even on Lxml, what the difference. - danilshik

1 answer 1

With XPath, this will be something like:

 //tbody/tr[@id="cpu1422"] 

If you need everything at all with any id :

 //tbody/tr[@id] 
  • your code will only find a specific element with this id, but I need everything that has any Id - danilshik
  • @danilshik See edit. - Ainar-G