Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Scraping contents of ::before ::after CSS Psuedo element using BeautifulSoup

I'm learning Web Scraping. I would like to know how can we fetch participants count from below element?

<li class="header-hero__stat header-hero__stat--participants">
   ::before
   "255,590 Participants"
   ::after
</li>

Code I've tried

soupy = bs(html,'lxml') 
ul = soupy.find('li',{'class':"header-hero__stats"})

returns None

Target page

like image 323
Adam Iqshan Avatar asked Aug 30 '25 16:08

Adam Iqshan


1 Answers

This is not content of pseudo-elements, but text content of li node, so

li = soup.find('li',{'class':"header-hero__stat--participants"}).text

should be enough to extract '255,601 Participants'

Use .text.split()[0] to get number only

like image 79
Andersson Avatar answered Sep 02 '25 04:09

Andersson