Let's assume we have code:
<tr class=" " somethingc1="" somethingc2="" somethingc3="" data-something="1" something="1something4" something_id="6something7">
<td class="text-center td_something">
<div>
<span doo="true" class="foo" style="left:70%;z-index:99;">
<span doo="true" class="foo" style="left:50%;z-index:90;">
<span doo="true" class="Kung foo" style="left:90%;z-index:95;">
</div>
</td>
</tr>
<tr class=" " somethingc1="" somethingc2="" somethingc3="" data-something="1" something="1something4" something_id="6something7">
<td class="text-center td_something">
<div>
<span doo="true" class="Kung foo" style="left:35%;z-index:95;">
</div>
</td>
</tr>
<tr class=" " somethingc1="" somethingc2="" somethingc3="" data-something="1" something="1something4" something_id="6something7">
<td class="text-center td_something">
<div>
<span doo="true" class="foo" style="left:99%;z-index:100;">
</div>
</td>
</tr>
How may I make a list using Bs4 in Python to find the highest value of 'left' in 'style' attrs keeping in mind that I do not want to take into consideration spans with class_ "Kung"
Desired result would be:
[70,False or NaN,99]
I've got it I should start with something like:
trs = soup.find_all('tr', attrs={"data-something": "1"})
List = list()
find_all('span',{'style': re.compile(r'^left:.')})
First, select all of the element whose
classcontainsfoo(whether or not it contains something else as well).In each case
element['class']will be a list of the items inclassfor the element, ie, either justfooorfooandKungin the case of this HTML. Thus a test for the length ofelement['class']is a test for the presence offooalone.element['style']gets the contents ofstylefor the element. Use a regex for the part of it we want, and add it to the list calledlefts.Edit:
Find the
trelements, then look for theelementswith classfoo. As before, include consideration of only those elements with just classfoonot bothfooandKung. Gatherleftstyle elements for these elements and then find the maximum values of them.