Answer the question
In order to leave comments, you need to log in
How to track the redirect and break the loop?
I can't understand the joke.
Yesterday the code below worked like clockwork and today the script immediately interrupts its work.
The essence of the script:
You need to run through all the pages while status_code is 200, and as soon as we stumble upon a redirect, the loop execution immediately stops.
import requests
class SSLV_Parser():
def __init__(self):
self.root_url = 'https://ss.com'
self.vacancies_today_url = 'https://ss.com/ru/work/are-required/today/page{}.html'
def calculate_pagination(self, url):
pages_count = 0
page = 1
while True:
response = requests.get(url.format(page), allow_redirects=False)
if response.status_code == 200:
page += 1
pages_count += 1
print(response.url)
else:
break
return pages_count
ss = SSLV_Parser()
ss.calculate_pagination(ss.vacancies_today_url)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question