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?