телеграмм бот

This commit is contained in:
inweems
2023-04-19 11:10:43 +03:00
parent 8d96d62299
commit 1dab6aae05
5 changed files with 119 additions and 5 deletions
+9 -1
View File
@@ -19,12 +19,20 @@ browser.get('https://www.ozon.ru/category/platya-zhenskie-7502/')
html_code = browser.page_source
soup = BeautifulSoup(html_code, 'lxml')
name = soup.find_all('span', class_="m2e e3m m3e m5e tsBodyL k7l l7k")
names = []
sale = soup.find_all('div', class_="eg1 g3e")
price = soup.find_all('span', class_="a2a-a2")
info = soup.find_all('span', class_="je4")
picture = soup.find_all('div', class_="k1m")
products = soup.find_all("div", class_="k7o o7k")
for product in products:
names.append(soup.find('span', class_="m2e e3m m3e m5e tsBodyL k7l l7k").text.strip())
print(names)
exit(0)
for i in range(20):
url = picture[i].find('img').attrs['src']
file_name = f"C:\\Users\\Honor\\Desktop\\учеба\\прога\\pictures\\{i}.jpg"
+37
View File
@@ -0,0 +1,37 @@
import telebot
import random
from telebot import types
f = open('C:\\Users\\Honor\\Desktop\\учеба\\прога\\тг_бот\\бот\\факт.txt', 'r', encoding='UTF-8')
facts = f.read().split('\n')
f.close()
f = open('C:\\Users\\Honor\\Desktop\\учеба\\прога\\тг_бот\\бот\\поговорка.txt', 'r', encoding='UTF-8')
thinks = f.read().split('\n')
f.close()
bot = telebot.TeleBot('5696445699:AAEPKQgUAs39DTLr_iyQvlaFAsJNFK8DMnc')
@bot.message_handler(commands=["start"])
def start(m, res=False):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1=types.KeyboardButton("Факт")
item2=types.KeyboardButton("Поговорка")
markup.add(item1)
markup.add(item2)
bot.send_message(m.chat.id, 'Нажми: \nФакт'
' для получения интересного факта\nПоговорка '
'— для получения мудрой цитаты ', reply_markup=markup)
@bot.message_handler(content_types=["text"])
def handle_text(message):
if message.text.strip() == 'Факт' :
answer = random.choice(facts)
elif message.text.strip() == 'Поговорка':
answer = random.choice(thinks)
bot.send_message(message.chat.id, answer)
bot.polling(none_stop=True, interval=0)