M
M
Maxim Mikhalko2022-02-19 23:07:14
Bots
Maxim Mikhalko, 2022-02-19 23:07:14

How to make the bot respond to the following message?

@bot.message_handler(commands=['search'])
def repeat_all_messages(message):
    bot.send_message(message.chat.id,'Введите запрос:')
    x = message.text
    print(x)
    search = message.text

    shmak = search.replace(' ', "+")

    URL = 'https://store.steampowered.com/search/?term='+ shmak

    headers = {
       'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041'
    }

    responce = requests.get(URL,headers=headers)
    soup = BeautifulSoup(responce.text, 'lxml')
    games = soup.find_all('a', class_='search_result_row ds_collapse_flag')

    for n,i in enumerate(games,start=1):
        title = i.find('div', class_='col search_name ellipsis').find('span', class_='title')
        try:
            price = i.find('div', class_='col search_price responsive_secondrow').text
        except:
            price = i.find('div', class_='col search_price discounted responsive_secondrow').find('strike').text

        link = i.get('href')

        x = f'{n}:{title.text}\n\n{price}\n{link}\n'
        bot.send_message(message.chat.id, x)
        if n == 10:
            break

bot.infinity_polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JiMoon, 2022-02-20
@Jimoon

if you can’t do something, write some code element you need, then stomp either on Stack Overflow or freelance (better, probably, freelance), because you don’t even have an error. You wrote the code - does it work incorrectly? Or are you too lazy to look for yourself?
https://google.gik-team.com/?q=%D0%BE%D1%82%D0%B2%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question