基于python_爬取51前程无忧-贵阳数据分析岗位

爬虫—51前程无忧
import csv, re, time
from bs4 import BeautifulSoup
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import Chrome, ChromeOptions

f = open('./贵阳数据分析.csv', 'a', encoding='utf-8', newline='')
writer = csv.writer(f)
writer.writerow(['岗位', '发布时间','薪资', '公司', '地址','经验', '其他'])

b = Chrome()


def get_net_data():

    b.get('https://www.51job.com/')
    search_input = b.find_element_by_css_selector('#kwdselectid')
    input('是否继续')
    search_input.send_keys('数据分析')
    search_input.send_keys(Keys.ENTER)

    while True:
        # 获取页信息
        page_div = b.find_element_by_css_selector('.rt.rt_page')
        pages = page_div.text.split('/')
        all_page = int(pages[-1])
        current_page = int(pages[0])

        # 获取网页源代码
        print(b.page_source)
        save_data(b.page_source)

        if current_page < 12:
            next = b.find_element_by_css_selector('.next')
            next.click()
        else:
            break


def save_data(html: str):
    soup = BeautifulSoup(html, 'lxml')
    time.sleep(2)
    all_job_div = soup.select('.j_joblist>.e')
    one_page_jobs = []
    for job_div in all_job_div:
        name = job_div.select_one('.jname.at').get_text()
        sal = job_div.select_one('.sal').get_text()
        company = job_div.select_one('.cname.at').get_text()
        job_url = job_div.select_one('.el').attrs['href']
        experience =job_div.select_one('.d.at').get_text()
        experience = experience.replace('  |  ', '-')
        Release_time = job_div.select_one('.time').get_text()
        Release_time = Release_time.replace('发布', ' ')
        # print(experience)
        other = job_div.select_one('.tags')
        if other:
            other = other.attrs['title']
        else:
            other = None
            print(Release_time)
        one_page_jobs.append([name,Release_time, sal, company, job_url, experience, other])
    writer.writerows(one_page_jobs)


if __name__ == '__main__':
    get_net_data()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值