[Python] If an error occurs during crawling repetition, I ask you to re-run the repetition statement.

Asked 2 years ago, Updated 2 years ago, 116 views

Hello, we are producing a Python crawling program through the request module.

After starting crawling in the program you are designing, due to a network error, etc.

I wonder if there is an error in the repetitive sentence or if the program stops, it makes the repetitive sentence turn again at that point.

 for z in range(len(excel_df1)):
                try:
                    #CrawlingCode
                except Exception as e:
                    write(e)

If len(excel_df1) is, for example, 5 when proceeding to a repeating statement like this, If there is a network error when z is 3, I want to start crawling again when it is 3 and finish I want to know how to do it!

python beautifulsoup

2022-09-19 23:32

1 Answers

for z in range(len(excel_df1)):
        count = 0
        while 1:
                try:
                    #CrawlingCode
                    break
                except Exception as e:
                    write(e)
                    count += 1
                if count > 2:
                    break


2022-09-19 23:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.