Home > Software engineering >  Find element with multiple classes using BeautifulSoup
Find element with multiple classes using BeautifulSoup

Time:12-07

How to get the h1 text "Mini Militia - Doodle Army 2 apk" https://www.apkmonk.com/app/com.appsomniacs.da2/

I tried this but I got None

title = soup.find('div', class_='col l8  s8')  

please Note there is multiple elements on the page that have classes "hide-on-med-and-down" and "hide-on-large-only"

<div class="col l8  s8">
        <h1 class="hide-on-med-and-down" style="font-size: 2em;">Mini Militia - Doodle Army 2 apk</h1>
        <h1 class="hide-on-large-only" style="font-size: 1.5em;margin:0px; padding: 0px;">Mini Militia - Doodle Army 2 apk</h1>
        <p class="hide-on-small-only" style="font-size: 1.2em;"><span class="item" style="display:none !important;"><span class="fn">Download Mini Militia - Doodle Army 2 APK Latest Version</span></span><b>App Rating</b>: <span class="rating"><span class="average">4.1</span>/<span class="best">5</span></span></p>
        <a class="hide-on-med-and-up" onclick="ga('send', 'event', 'nav', 'similar_mob_link', 'com.appsomniacs.da2');" style="font-size: 1.2em;" href="#similar">(<b>Similar Apps</b>)</a>
</div>

CodePudding user response:

This will help you.

title = soup.find("h1", {'class':'hide-on-med-and-down'}).text

CodePudding user response:

What happens?

There are two <h1> on site with same content only the class names are different, to control what size, ... should displayed on different resolutions

How to fix?

Cause content is identical, just select the first <h1> in tree to get your result, class names do not matter in this case, cause result is always the same:

title = soup.find('h1').text

Output

Mini Militia - Doodle Army 2 apk
  • Related