【问题标题】:pyTelegramBotAPI inline google search enginepyTelegramBotAPI 内联谷歌搜索引擎
【发布时间】:2022-12-03 20:17:39
【问题描述】:
@bot.inline_handler(func=lambda query: len(query.query) > 0)
    def query_text(query):
        sleep(6)
        text=query.query
        html=requests.get(f'https://google.com/search?q={text}')
        # print(html.status_code)
        open('index.html','w', encoding='utf-8').write(html.text)
        soup=BeautifulSoup(html.text, 'html.parser').find_all('div',{"class":"***********"})
        for i in soup:
            fk.append(types.InlineQueryResultArticle(id=str(len(fk)), title=f"{i.find('h3').get_text()}",description=f"{i.find('div',{'class':'**********'}).get_text()}",input_message_content=types.InputTextMessageContent(message_text=i.find('a').get('href').replace('/url?q=','https://google.com/url?q=')),hide_url=True,url=i.find('a').get('href').replace('/url?q=','https://google.com/url?q='),thumb_url='https://w7.pngwing.com/pngs/338/520/png-transparent-g-suite-google-play-google-logo-google-text-logo-cloud-computing.png', thumb_width=30, thumb_height=30))
            print(i.find('a').get('href').replace('/url?q=','')+'\n')
        sleep(2)
        bot.answer_inline_query(query.id, fk)

当我写@bot google 请求时
Bot 将其视为 g go goo google
是什么导致了错误
"A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: query is too old and response timeout expired or query ID is invalid"
如何使文本输入超时,使其不响应每个字母?

【问题讨论】:

    标签: python-3.x inline py-telegram-bot-api telebot


    【解决方案1】:

    我认为,错误在于您解析数据的方式。至少需要 8 秒(基于睡眠)才能到达答案方法。电报内联查询在被认为是旧的之前只有几秒钟的时间,因此,最好在调用bot.answer_inline_query() 之后处理数据,然后使用bot.send_message() 将其发送给用户

    我不确定它如何与异步代码一起使用。 如果您找到其他解决方案,请告诉我:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-06
      • 2019-09-19
      • 1970-01-01
      • 2011-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多