Не могу понять, почему парсит только 1 страницу. При добавлении страницы переход не работает. Подскажите, где ошибка?
data = []
#page = 2
res = requests.get('https://ryvok.ru/instrumenty/shlifmashiny/')
#res = requests.get('https://ryvok.ru/instrumenty/shlifmashiny/?page={page}')
soup = BeautifulSoup(res.text, 'html')
elements = soup.find_all('div', class_ = 'app-product-card__wrap')
for e in elements:
data.append({
'title': e.find('div', class_ = 'app-product-card__title').text.strip(),
'status': e.find('div', class_ = 'app-product-card__status_color-success app-product-card__status').text.strip(),
'price': e.find('div', class_ = 'app-product-card__price').text.strip().replace('\xa0','').replace(' ₽',''),
})
Код целиком
data = []
page = 1
max_page = 1
while page <= max_page:
res = requests.get('https://ryvok.ru/instrumenty/shlifmashiny/?page={page}')
soup = BeautifulSoup(res.text, 'html')
elements = soup.find_all('div', class_ = 'app-product-card__wrap')
for e in elements:
data.append({
'title': e.find('div', class_ = 'app-product-card__title').text.strip(),
'status': e.find('div', class_ = 'app-product-card__status_color-success app-product-card__status').text.strip(),
'price': e.find('div', class_ = 'app-product-card__price').text.strip().replace('\xa0','').replace(' ₽',''),
})
pagination = soup.find('div', class_ = 'ui-pagination__numbers')
pages = [int(p.text.strip()) for p in pagination.find_all('div', class_ = 'ui-pagination__number')]
int_pages = []
for p in pages:
try:
n = int(p)
int_pages.append(n)
except:
continue
max_page = max(int_pages)
page += 1
print(page, max_page)