0

I have a code that parses a website and returns a dataframe. Sometimes, the website is blank i.e. page loads however there is no data to scrape from the page. My code returns a NoneType error when it builds the dataframe.

How can I workaround it?

Code:

class GameData:

    def __init__(self):
        self.date = []
        self.time = []
        self.game = []
        self.score = []
        self.home_odds = []
        self.draw_odds = []
        self.away_odds = []
        self.country = []
        self.league = []
    ....
    
    game_data = GameData()
    
    ....


    if __name__ == '__main__':
    
        results = None
    
        for url in urls:
            game_data = parse_data(url)
            result = pd.DataFrame(game_data.__dict__)
            if results is None:
                results = result
            else:
                results = results.append(result, ignore_index=True)

Error:

result = pd.DataFrame(game_data.__dict__)
AttributeError: 'NoneType' object has no attribute '__dict__'

If there is no data on the page, I want to parse an empty dataframe with just the headers.

How can I do it?

0 Answers0