Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

Beautifoul soup - getting all li elements from ul where only first li has specific class name

$
0
0

I have unordered list like this in HTML:

<ul> 
<li class="label">Equipement</li>
<li>Aluminum tyres</li>
<li>4x4</li>
<li>3. stop lights</li>
<li>Bluetooth</li>
</ul>

Only first li element in the ul list contains title of the list, other elements contain list of features that needs to be extracted in plain text. I know how to locate that first li but I don't know how to select all other elements.

Consider that this ul doesn't have class and its in the HTML document with a lot of other ul elements. I can locate that ul through li with:

 (li.previousSibling).get_text() 

but cannot extract all elements with get_text() , I'm getting:

AttributeError: 'NavigableString' object has no attribute 'get_text'

Also I need to extract all li except first one which holds title. I have several ul on page like this and they are all variable in lenght (have more or less li elements).

EDIT

My code so far. I'm finding elements with:

 carBasics = soup.select('li.label')

    for li in carBasics:
         if li.contents[0]=="Equipement":
            carAdditionalEquipement = (li.previousSibling).find_all('li')

AttributeError: 'NavigableString' object has no attribute 'get_text'


Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>