I wanted to search within the tag:
<div id="cmeProductSlatePaginiationTop" class="cmePaginiation">
<ul>
<li class="disabled">
<li class="active">
<li class="away-1">
<li>
</ul>
</div>
Basically, I want to count the number of occurunces of <li ..>
in this div. However, when I used beautifulsoup, I can't get the tags in between the div
soup = BeautifulSoup(resp)
tags = soup.find('div', attrs = {'class' : 'cmePaginiation'})
print tags
>>> <div id="cmeProductSlatePaginiationTop" class="cmePaginiation"> </div>
Is there a way to count the number of instances of li
(In this example 4)?
In order to use multiple tags or elements, we have to use a list or dictionary inside the find/find_all() function. find/find_all() functions are provided by a beautiful soup library to get the data using specific tags or elements. Beautiful Soup is the python library for scraping data from web pages.
Step 1: The first step will be for scraping we need to import beautifulsoup module and get the request of the website we need to import the requests module. Step 2: The second step will be to request the URL call get method.
Use find_all
:
div = soup.find('div', id='cmeProductSlatePaginiationTop')
lis = div.find_all('li')
num_lis = len(lis)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With