from aiogram import types, executor, Dispatcher, Bot
from bs4 import BeautifulSoup
import requests
bot = Bot('5703223554:AAFPcIBNJv_Xr_eJC1nDepG0lZKW6z1Zk1U')
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def start(massage: types.message):
await bot.send_message(massage.chat.id, 'Введите название товара с OZON')
@dp.message_handler(content_types=['text'])
async def parser(message: types.message):
url = "https://www.ozon.ru/category/videokarty-15721/?category_was_predicted=true&deny_category_prediction=true&from_global=true&text=" + message.text
request = requests.get(url)
soup = BeautifulSoup(request.text, "html.parser")
all_links = soup.find_all("a", class_="tile-hover-target")
for link in all_links:
url = "https://www.ozon.ru/" + link["href"]
request = requests.get(url)
soup = BeautifulSoup(request.text, "html.parser")
name = soup.find("h1", class_="on1")
price = name.find("a").text
name.find("a").extract()
name = name.text
img = soup.find("div", class_ = "kt9")
img = img.findChildren("img")[0]
img = "https://cdn1.ozone.ru/s3/multimedia-n/wc50/6367968875.jpg"
await bot.send_photo(message.chat.id, img, caption= name + price + f"</i>\n<a href='{url}'>Ссылка на сайт</a>", parse_mode="html")
executor.start_polling(dp)
for link in all_links:
...
await bot.send_photo(...)