BeautifulSoup: Pull p tag while between defined h2 tags

Viewed 1111

this has puzzled me for a bit now. I am trying to pull all of the text from 'p' tags under 'h2' tags by names of "New Fundings" and "New Funds". Number of 'p' tags aren't consistent for each page, so I was thinking of some sort of while loop and what I tried didn't work. The format for each

tag is often the company name with 'strong', then listing text and other 'strong' tags for who funded/invested.

Once I can parse it properly, the goal is to export the company name from 'strong' tag with the proceeding text and the investing companies/people (from following 'strong' tags in the 'p' block to do some data analysis.

Any help would be appreciated - yes, I have looked through various other help pages, but the attempts I've made haven't been successful, so I came here.

import requests
page = requests.get("https://www.strictlyvc.com/2017/06/13/strictlyvc-june-12-2017/")
page
page.content
from bs4 import BeautifulSoup
soup = BeautifulSoup(page.content, 'html.parser')
entrysoup = soup.find(class_ = 'post-entry')

// trying to pull the right paragraphs but these only select the NEXT one, I want all of the

tags under 'New Fundings' & 'New Funds' (basically, until the next tag that isn't either of those.

print(entrysoup.find('h2', text = 'New Fundings').find_next_sibling('p'))
print(entrysoup.find('h2', text = 'New Funds').find_next_sibling('p'))

// This was closer, but I wasn't sure how to get it to stop when it hit the non-New Fundings/New Funds tags

for strong_tag in entrysoup.find_all('strong'):
    print (strong_tag.text, strong_tag.next_sibling)
1 Answers
Related