Не выводит результат в таблицу, столбцы получаются разных размеров
А разных размеров они из-за того, что когда товара нет в наличии, то цена не указывается и пункт цены просто не заполняется
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
from collections import OrderedDict
url_template = "https://estel-shop.ru/catalog/ukhod/?PAGEN_1="
file_name = 'ukhod.xlsx'
page = 1
maxpage = 17
href = []
title = []
cost = []
while True:
url = url_template + str(page)
r = requests.get(url)
r.encoding = 'utf-8'
soup = bs(r.text, 'html.parser')
product_names = soup.find_all('div', class_='item-title')
product_price = soup.find_all('span', class_='price_value')
if page <= maxpage:
for name in product_names:
href.append('https://estel-shop.ru' + name.a['href'])
title.append(name.text)
for price in product_price:
cost.append(price.text)
page += 1
print(url)
else:
break
result_list = {'href': href, 'title': title, 'cost': cost}
df = pd.DataFrame(data=result_list)
df.to_excel(file_name)
Пробовал так, но просто ничего не происходит
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
from collections import OrderedDict
url_template = "https://estel-shop.ru/catalog/ukhod/?PAGEN_1="
file_name = 'ukhod.xlsx'
page = 1
maxpage = 17
href = []
title = []
cost = []
stock = []
while True:
url = url_template + str(page)
r = requests.get(url)
r.encoding = 'utf-8'
soup = bs(r.text, 'html.parser')
product_names = soup.find_all('div', class_='item-title')
product_price = soup.find_all('span', class_='price_value')
product_stock = soup.find_all('div', class_='items-stock')
if page <= maxpage:
for stock_check in product_stock:
stock.append(stock_check.text)
if stock != 'Нет в наличии':
for name in product_names:
href.append('https://estel-shop.ru' + name.a['href'])
title.append(name.text)
for price in product_price:
cost.append(price.text)
page += 1
print(url)
else:
break
result_list = {'href': href, 'title': title, 'cost': cost}
df = pd.DataFrame(data=result_list)
df.to_excel(file_name)