Skip to content
Advertisement

Python Web Scraping – handling page 404 errors

I am performing web scraping in via Python Selenium Chrome headless driver which involves executing a loop:

JavaScript

However, sometime the page might not exist when the customer ID is certain number. I have no control over this and the code stops with page not found 404 error. How do I ignore this though and just move on with the loop?

I’m guessing I need a TRY….EXCEPT though?

Advertisement

Answer

You can check the page body h1 tag what the text appeared when it comes 404 error and then you can put that in if clause to check if not then go inside the block.

JavaScript

Or

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement