dimanche 25 avril 2021

If statement to continue appending data

My code appends data from hundreds of webpages. Some of these webpages have no data. I need my code to move to the next page when there is no data to append on the webpage. When there is no data to append on the webpage 'venue' = the word 'null'.

My code:

for meet in range(5163022,5163024):
    request = requests.get(f'https://api.racing.com/v1/en-au/meet/details/{meet}',
    headers={'User-Agent': 'Mozilla/5.0'})
    json = request.json()
    venue = json['meet']['venueAbbr']
    for meet in json['raceCollection']:
        date = meet['date']
        raceno = meet['raceNumber']
        distance = meet['distance']
        racetime = meet['raceTime']
        data.append((date, venue, raceno, distance, racetime))

What should I use as an if statement and where should I place the if statement?

Aucun commentaire:

Enregistrer un commentaire