I am trying to scrape some content from different urls. The first URL looks like (fake examples): "https://something.com/something-1", the second: "https://something.com/somethings-2-mix" etc and the third might go back looking like the first one. I am trying to build in exceptions so that my code can handle these different urls. I have the following code till now which of course does not work - as I think the code is not handling the 404 exceptions as it should.
url1 = 'https://somthing.com/something-'
url2 = 'https://somthing.com/somethings-'
url3 = '-mix'
for r in list(range(1,2)):
url = f'{url1}{r}'
browser.get(main_url)
soup = BeautifulSoup(browser.page_source, "html.parser")
if "404" in soup.find("body").text:
browser.quit()
urlalt = f'{url2}{r}{url3}'
browser.get(urlalt)
Any ideas/suggestions/answers will be very much appreciated. I apologise in advance if my search here hasn't been exhaustive. Thank you very much!