https://pastein.ru/t/jm5

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

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


#pip install requests, fake_useragent, bs4, lxml

import requests
import fake_useragent
from bs4 import BeautifulSoup

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

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

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

    return res

def main(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,
        'experience': type_of_years_of_experience,
        'search_period': 0
    }
    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",'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
        }
        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")
            print(cur_job.text, "-", cur_link['href'])
            # print(cur_city.text)

if __name__ == '__main__':
    desired_job = input("Введите профессию:\n")
    desired_city = input("Введите название города:\n")

    TYPES_OF_YEARS_OF_EXPERIENCE = ['noExperience', 'between1And3', 'between3And6', 'moreThan6']
    MINIMUM_YEARS_OF_EXPERIENCE = [0, 1, 3]
    years_of_experience = int(input("Введите количество лет опыта работы в этой профессии:\n"))

    TYPES_OF_WORK = ['MONTH', 'SHIFT', 'HOUR', 'FLY_IN_FLY_OUT', 'SERVICE']
    types_of_work = input("Выберите тип оплаты:\n1 - за месяц, 2 - за смену, 3 за час, 4 - за вахту, 5 - за услугу\n").split()
    types_of_work = [int(x) - 1 for x in types_of_work]

    desired_salary = input("Введите минимальную зп для каждого типа работы в том же порядке:\n").split()
    desired_salary = [int(x) for x in desired_salary]

    without_salary = 'да' in input("Показывать объявления без указанной зп? (Да/Нет):\n").lower()

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

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