federico zampu
federico zampu

Reputation: 99

Python + scrape strong within ul

I'm trying to scrape the information under the strong tag within ul. I'm using the following code to extract strong:

stats = soup.find('ul', attrs = {'class' : 'inline-stats section'})
print(stats)

The print is shown in the image below. Now, I need to extract the information within strong; that is 8.0 , 49.41 and 6.10.

I tried to loop over values in stats but always get errors and got stuck.

Can anyone help me with this?

<ul class="inline-stats section">
<li>
<strong>8.0<abbr class="unit" title="kilometers">km</abbr></strong>
<div class="label">Distance</div>
</li>
<li>
<strong>49:41</strong>
<div class="label">
<span class="glossary-link run-version" data-glossary-term="definition-moving-
time"></span>
Moving Time
</div>
</li>
<li>
<strong>6:10<abbr class="unit" title="minutes per kilometer">/km</abbr></strong>
<div class="label">
<span class="glossary-link run-version" data-glossary-term="definition-moving-
time">
Pace
</span>
</div>
</li>
</ul>

Upvotes: 2

Views: 192

Answers (1)

Rinogg
Rinogg

Reputation: 186

Try this:

stats = soup.find('ul', attrs = {'class' : 'inline-stats section'}).findAll("strong")

Add:

for i in stats:
    print i

Upvotes: 1

Related Questions