Answer the question
In order to leave comments, you need to log in
Python code not working. Telebot?
Hello everyone, my python code is not working. Bottom line - I wanted to make a task parser from the habr< site, I did everything, but I only get one task and that old one. I don't understand what to do
import config
import telebot
import requests
from telebot import types
from telebot import apihelper
from bs4 import BeautifulSoup as BS
apihelper.proxy={"https": "socks5://82.223.120.213:1080"}
bot = telebot.TeleBot("ip key")
r=requests.get("https://freelance.habr.com/tasks")#
html=BS(r.content,"html.parser") #
for el in html.select(".task__column_desc"): #ПАРСИНГ ЗАДАНИЙ С САЙТА https://freelance.habr.com/tasks
title=el.select(".task__title > a")
@bot.message_handler(commands=["start","work"])
def start_message(message):
#keyboard
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1=types.KeyboardButton("Задания на freelance")
item2=types.KeyboardButton("Залогиниться на сайте")
markup.add(item1,item2)
bot.send_message(message.chat.id, 'Дорбро пожаловать , {0.first_name}!\n - <b>{1.first_name}</b>, бот созданный для проверки списка заданий на сайте https://freelance.habr.com/tasks'.format(message.from_user, bot.get_me()),
parse_mode="html", reply_markup=markup)
@bot.message_handler(content_types=["text"])
def lola(message):
if message.text=="Задания на freelance":
bot.send_message(message.chat.id, title[0].text)
bot.polling()
Answer the question
In order to leave comments, you need to log in
you save only one task, save all. and choose what you need
from pprint import pprint
import requests
from bs4 import BeautifulSoup as BS
r = requests.get("https://freelance.habr.com/tasks") #
html = BS(r.content, "html.parser") #
title = list()
for el in html.select(".task__column_desc"): # ПАРСИНГ ЗАДАНИЙ С САЙТА https://freelance.habr.com/tasks
title.extend(el.select(".task__title > a"))
pprint(title)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question