ImportError:无法从“电报”导入名称“更新”

问题描述 投票:0回答:0

来自电报导入更新 导入错误:无法从“电报”导入名称“更新”

import requests
from bs4 import BeautifulSoup
from telegram import Update


TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN'


def start(update: Update, context: CallbackContext):
    context.bot.send_message(chat_id=update.effective_chat.id, text="Welcome to the product search bot! Please enter a product name to search for.")


def search_product(update: Update, context: CallbackContext):
    product_name = update.message.text
    url = f'https://example.com/search?q={product_name}'
    response = requests.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')
    products = soup.find_all('div', class_='product')

    for product in products:
        name = product.find('h3', class_='product-name').text.strip()
        price = product.find('div', class_='product-price').text.strip()
        context.bot.send_message(chat_id=update.effective_chat.id, text=f'{name}\n{price}')


def main():
    updater = Updater(TOKEN)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(MessageHandler(Filters.text & ~Filters.command, search_product))
    updater.start_polling()
    updater.idle()


if __name__ == '__main__':
    main()

我尝试 pip uninstall python-telegram-bot pip 安装 python-telegram-bot --upgrade --force-reinstall 从电报导入更新 但它没有帮助

python telegram-bot python-telegram-bot
© www.soinside.com 2019 - 2024. All rights reserved.