1

I have this html code that is repeating multiple times:

     <div class="Company_line-logo image-loader-target" data-image-loader-height="47" data-image-loader-height-mobile="47" data-image-loader-src="/var/fiftyPartners/storage/images/startups/woleet/3261-1-fre-FR/Woleet_company_line_logo.png" data-image-loader-src-mobile="/var/fiftyPartners/storage/images/startups/woleet/3261-1-fre-FR/Woleet_company_line_logo_mobile.png" data-image-loader-width="189" data-image-loader-width-mobile="189" style='background-image:url("http://en.50partners.fr/var/fiftyPartners/storage/images/startups/woleet/3261-1-fre-FR/Woleet_company_line_logo.png");'></div>   
<h5 class="Company_line-title">Woleet</h5>
        <div class="Company_line-description">

By using:

    for blocks in soup:
        block = soup.find('a', class_='Company_line logo-contains-name').find('h5').get_text()

I can get what I want that is "Woleet" in between the h5 tags.

I tried to iterate this to get all of them:

    block = soup.find('a', class_='Company_line logo-contains-name')
    for name in block:
        names = block.find_all('h5')

it returns only 1 h5 class="Company_line-title">Woleet</h5 whereas I should get 50 names like "Woleet".

How can I iterate this and get the text from all h5 tags?

Thanks!

Steven
  • 119
  • 2
  • 4
  • 15
  • I don't understand your for loops. You define some iterable, (blocks, name) and never iterate over them? And as far as I remember, you don't need a loop to run `find_all()` method on a soup object. – serali Sep 29 '21 at 08:13

1 Answers1

0

I could iterate and get the text from all the h5 tags with this code:

    main_block = soup.find(class_='Node_full startups content_class_folder')
    block = [h5.get_text() for h5 in main_block.find_all('h5', class_='Company_line-title')]

I'm wondering if there is another way to extract the text from the h5 tags.

Steven
  • 119
  • 2
  • 4
  • 15