0

How can I retry url from list if ValueError?

Error:

raise ValueError("No tables found")
ValueError: No tables found

Or other exceptions.

Can use if ValueError then driver.refresh(2wice)

but I dont know location in the code:

if __name__ == '__main__':

    results = None

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

Maximum retry 2

1 Answer 1

1

You can put the entire thing in a try/except block and if it encounters a ValueError at some point, you can put the same code under except and it will retry it.

if __name__ == '__main__':

    results = None

    for url in urls:
        try:
            game_data = parse_data(url)
            if game_data is None:
                continue
            result = pd.DataFrame(game_data.__dict__)
            if results is None:
                results = result
            else:
                results = results.append(result, ignore_index=True)
        except ValueError:
            game_data = parse_data(url)
            if game_data is None:
                continue
            result = pd.DataFrame(game_data.__dict__)
            if results is None:
                results = result
            else:
                results = results.append(result, ignore_index=True)

Throw in a finally: after the except block with the same spacing if you want it to do something after it's tried twice.

Sign up to request clarification or add additional context in comments.

1 Comment

ValueError(): time.sleep(1) browser.refresh Will this work if I were to refresh?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.