I have a long html but here's a fragment:
<tr>
<td data-bind="text:name, css: isActive() ? 'variable-active': 'variable-inactive'" class="variable-active">Vehicle</td>
<td data-bind="text:value">Ford</td>
</tr>
<tr>
<td data-bind="text:name, css: isActive() ? 'variable-active': 'variable-inactive'" class="variable-inactive">Model</td>
<td data-bind="text:value">Focus</td>
</tr>
I want to get all the content tags based on if it is "variable-active", and then get the value from the next 'td' tag. In this case, as the second class tag is "variable-inactive", the output should be:
"Vehicle - Ford"
I managed to get the first tags based on the "variable-active" but I can't get the second values from the other tags. This is my code:
from bs4 import BeautifulSoup
with open ("html.html","r") as f:
doc = BeautifulSoup(f,"html.parser")
tag = doc.findAll("tr")[0]
print(tag.findAll(class_="variable-active")[0].contents[0]) #vehicle
tag.findNextSibling(class_="variable-active") # nothing