Categories
Mastering Development Software

Python BeautifulSoup: Function to stop a soup.find_all_next() at an exact point in the soup?

this is my first post here on stackexchange. I am new at python and just started a month or two ago. The project I am working on is a webscraper to take market data off of marketwatch.com. The developer code I am looking at is at the following site.

https://www.marketwatch.com/investing/stock/ba/financials/balance-sheet

The scraper I built crawls though multiple pages of a website.

I am trying to use the find_all_next(string=True) It captured all the data I was looking for except for the fact that I get string text that I do not need starting at Copyright 2020.

I want to build a break function that stops the search when it hits ‘Copyright 2020’. After researching for a few hours I am still not sure how to go about it.

I feel like I am in the right direction but I do not know how to build a function to stop its search at an exact point.

for cont3 in boeing_financials:
    table_data = cont3.find_all('table', class_='crDataTable')
    for data in table_data:
        d = data.find_all('tbody')
        for string in d:
            string_cheese = string.find_all_next(string=True)
            print(string_cheese)
            break

Leave a Reply

Your email address will not be published. Required fields are marked *