https://pastein.ru/t/mc5

  скопируйте уникальную ссылку для отправки

Загрузка данных


#pip install requests, fake_useragent, bs4, lxml
#pip install telebot

import requests
import fake_useragent
from bs4 import BeautifulSoup

import telebot
from telebot import types

user_agent = fake_useragent.UserAgent().random
HEADER = {'user-agent': user_agent}
URL = 'https://brest.rabota.by/search/vacancy'

API_TOKEN = '8224165507:AAECDEE1kL-Zgy2OeT77AX2u_7N4KMY_L3M'

bot = telebot.TeleBot(API_TOKEN)

def find_number(s) -> int:
    res = 0

    for c in s:
        if '0' <= c <= '9':
            res = res * 10 + int(c)

    return res

def get(message, desired_job, desired_city, type_of_years_of_experience, type_of_work, salary, without_salary):
    params = {
        'area': 16,
        'text': desired_job,
        'page': 0,
        'items_on_page': 20,
        'salary_mode': type_of_work,
        'salary': salary,
        'experience': type_of_years_of_experience,
        'search_period': 0,
        'search_field': 'name'
    }
    if not without_salary:
        params['label'] = 'with_salary'

    response = requests.get(URL, params=params, headers=HEADER)
    #print(response.url)
    soup = BeautifulSoup(response.text, "lxml")

    amount_of_vacancies = find_number(soup.find("h1", class_='magritte-text___gMq2l_7-0-2 magritte-text-overflow___UBrTV_7-0-2 magritte-text-typography-small___QbQNX_7-0-2 magritte-text-style-primary___8SAJp_7-0-2').text)
    amount_of_pages = (amount_of_vacancies + 19) // 20

    for page in range(amount_of_pages):
        params = {
            'area': 16,
            'text': desired_job,
            'page': page,
            'items_on_page': 20,
            'salary_mode': type_of_work,
            'salary': salary,
            'experience': type_of_years_of_experience,
            'search_period': 0,
            'search_field': 'name'
        }
        if not without_salary:
            params['label'] = 'with_salary'

        response = requests.get(URL, params=params, headers=HEADER)
        #print(response.url)
        soup = BeautifulSoup(response.text, "lxml")

        blocks = soup.find_all("div", class_='vacancy-info--ieHKDTkezpEj0Gsx')

        for block in blocks:
            block_header = block.find("h2", class_='bloko-header-section-2')
            cur_job = block_header.find("span", class_='magritte-text___tkzIl_6-0-2')

            block_info = block.find("div", class_='info-section--YaC_npvTFcwpFd1I')
            block_city_arr = block_info.find_all("div", class_='narrow-container--HaV4hduxPuElpx0V')
            block_city = block_city_arr[-1]

            cur_city = block_city.find("span", class_='magritte-text___pbpft_4-1-0 magritte-text_style-primary___AQ7MW_4-1-0 magritte-text_typography-label-3-regular___Nhtlp_4-1-0')
            if not desired_city.lower() in cur_city.text.lower():
                continue

            cur_link = block.find("a")
            bot.send_message(message.chat.id, f'{cur_job.text} - {cur_link['href']}', parse_mode='html')
            # print(cur_city.text)

session = {}

cur = 0
@bot.message_handler(commands=['start'])
def start(message):
    session[message.from_user.id] = {}
    data = session[message.from_user.id]
    data['step'] = 0

    bot.send_message(message.chat.id, 'Привет! Я дам все вакансии на rabota.by', parse_mode='html')
    bot.send_message(message.chat.id, 'Введите профессию', parse_mode='html')

@bot.message_handler(content_types=['text'])
def input_info(message):
    data = session[message.from_user.id]

    match data['step']:
        case 0:
            data['desired_job'] = message.text
            bot.send_message(message.chat.id, 'Введите название города', parse_mode='html')
        case 1:
            data['desired_city'] = message.text
            bot.send_message(message.chat.id, 'Введите количество лет опыта работы в этой профессии', parse_mode='html')
        case 2:
            data['years_of_experience'] = int(find_number(message.text))
            bot.send_message(message.chat.id, 'Выберите тип оплаты:\n1 - за месяц, 2 - за смену, 3 за час, 4 - за вахту, 5 - за услугу', parse_mode='html')
        case 3:
            data['types_of_work'] = message.text.split()
            data['types_of_work'] = [int(x) - 1 for x in data['types_of_work']]
            bot.send_message(message.chat.id, 'Введите минимальную зп для каждого типа работы в том же порядке', parse_mode='html')
        case 4:
            data['desired_salary'] = message.text.split()
            data['desired_salary'] = [int(x) for x in data['desired_salary']]
            bot.send_message(message.chat.id, 'Показывать объявления без указанной зп? (Да/Нет)', parse_mode='html')
        case 5:
            data['without_salary']= 'да' in message.text.lower()
            bot.send_message(message.chat.id, 'Все данные получены, сейчас начнёться поиск', parse_mode='html')

            main(message)
            del session[message.from_user.id]
            bot.send_message(message.chat.id, 'Поиск окончен\n<code>/start</code> для нового запроса', parse_mode='html')

    data['step'] += 1

TYPES_OF_YEARS_OF_EXPERIENCE = ['noExperience', 'between1And3', 'between3And6', 'moreThan6']
MINIMUM_YEARS_OF_EXPERIENCE = [0, 1, 3]
TYPES_OF_WORK = ['MONTH', 'SHIFT', 'HOUR', 'FLY_IN_FLY_OUT', 'SERVICE']

def main(message):
    data = session[message.from_user.id]

    for i in range(len(MINIMUM_YEARS_OF_EXPERIENCE)):
        if data['years_of_experience'] >= MINIMUM_YEARS_OF_EXPERIENCE[i]:
            for j in range(len(data['types_of_work'])):
                get(message, data['desired_job'], data['desired_city'], TYPES_OF_YEARS_OF_EXPERIENCE[i], TYPES_OF_WORK[data['types_of_work'][j]], data['desired_salary'][j], data['without_salary'])

    if data['years_of_experience'] >= 6:
        for j in range(len(data['types_of_work'])):
            get(message, data['desired_job'], data['desired_city'], TYPES_OF_YEARS_OF_EXPERIENCE[-1], TYPES_OF_WORK[data['types_of_work'][j]], data['desired_salary'][j], data['without_salary'])

bot.infinity_polling()