gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
видоизмени код так, чтобы он выполнял такие действия с каждым товаром на странице,…
- User
видоизмени код так, чтобы он выполнял такие действия с каждым товаром на странице, вносил данные в базу данных chat_i = update.message.chat_id update.message.reply_text('Идет поиск товара. Если бот долго не отвечает, то возможно он не может найти данный товар. В таком случае обращайтесь к @egvv6, он проверит наличие товара.') query = update.message.text url = f'https://www.poizon.us/search?q={query}&options%5Bprefix%5D=last'
response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') link = soup.select_one('a.full-unstyled-link') if link is not None: href = link.get('href') if href is not None: full_link = 'https://www.poizon.us' + href else: update.message.reply_text('Ссылка не найдена') response = requests.get(full_link) soup = BeautifulSoup(response.text, 'html.parser') photo_selector = '#Thumbnail-template--16663852253403__main-1' photo_links = soup.select_one(photo_selector).get('srcset').split(', ') photo_link = photo_links[0].split(' ')[0] size_selector = 'div.product-popup-modal__content-info:nth-child(1) > variant-radios:nth-child(1) > fieldset:nth-child(2) > label:nth-child(3) > div:nth-child(1)' price_selector = 'div.product-popup-modal__content-info:nth-child(1) > variant-radios:nth-child(1) > fieldset:nth-child(2) > label:nth-child(3) > div:nth-child(2)' size_element = soup.select_one(size_selector) if size_element is not None: size = size_element.text.strip() else: size = 'Размер не найден' price_element = soup.select_one(price_selector) if price_element is not None: price = price_element.text.strip() else: price = 'Цена не найдена' name_element = soup.select_one('div.product__title > h1:nth-child(1)') if name_element is not None: name = name_element.text.strip() else: name = 'Название не найдено' info_element = soup.select_one('#ProductAccordion-ea1014ee-ae9d-4eee-b23c-d2dfe9ba75b4-template--16663852253403__main') if info_element is not None: info = info_element.text.strip() else: info = 'Информация не найдена' urls = photo_link.replace("//", "https://") url = urls+'111' photo_lin = photo_link.replace('//cdn.shopify.com', 'https://cdn.shopify.com') update.message.reply_text(f'Название: {name}\nРазмер: {size}\nИнформация: {info}') update.message.reply_text(f"цена: {price} (Цена является ориентировочной, за точной информацией можете обращаться к @egvv6.Обычно цена товара значительно меньше указанной здесь") bot.send_photo(chat_id=chat_i, photo=url) - Assistant