Xpath and attributes of the father

0

I'm scraping a web with the following structure

<tbody>
   <tr class='Leaguestitle'>...<\tr>
   <tr id='tr1_abababa'>..<\tr>
   <tr id='tr2_abababa'>..<\tr>
   .
   .
   <tr id='tr1_acacaca'>..<\tr>
   <tr id='tr2_acacaca'>..<\tr>
   <tr align='center'>..<\tr>
   .
   .
   <tr id='tr1_cbcbcbc'>..<\tr>
   <tr id='tr2_cbcbcbc'>--<\tr>
   <\tbody>

Each node then has its children with relevant information. To get the nodes I want, I use an xpath:

allrows=table.find_elements_by_xpath(
        './/tr[@class="Leaguestitle"] | .//tr[contains(@id,"tr1")] | .//tr[@align="center"]')

Goal for row in allrows:

The problem is that to know which type of 3 each node belongs to, I need that in the row node the tr tag appears, while with that search I only get the children of each node tr

I have tried to solve it in the following way:

row=row.find_element_by_xpath('..')

That theoretically returns the parent node, which I see happening when I do

print(row.get_attribute('innerHTML'))

However, when I try to filter according to the attributes of each node tr so much

row.get_attribute('class')

as

row.get_attribute('id')

It returns them to me as empty for all nodes, when I should not. What am I doing wrong?

    
asked by puppet 16.12.2017 в 23:08
source

1 answer

0

Maybe what is not quite right is the xpath and the way to use the OR, I use them for example in the following way:

.//tr[@class="Leaguestitle" or contains(@id,"tr1") or @align="center"]

I would also check the length of the list of items, once they are found. To ensure that you find them and they are what you need.

Anyway try to improve the question because it is not very clear which objects are exactly what you want to get from that piece of html.

    
answered by 18.12.2017 в 08:37