爬虫实战:爬取前程无忧(51job)python相关职位信息

本文介绍了如何使用Python爬虫技术,详细解析爬取前程无忧(51job)网站上的Python相关职位信息,包括职位名称、公司、薪资等关键数据,从而实现对招聘信息的有效抓取和分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import requests
from bs4 import BeautifulSoup
import re
import time

requests.adapters.DEFAULT_RETRIES = 3
strat_url = 'https://search.51job.com/list/030000%252C00,000000,0000,00,9,99,python,2,1.html'
ua = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36'}
resp = requests.get(strat_url,headers = ua)
resp.encoding = 'gb2312'
pages = int(re.findall(r'共(\d+)页',resp.text)[0]) #匹配总页数,确定循环次数
info_list = [] 

def get_info(url):
    resp = requests.get(url,headers = ua)
    resp.encoding = 'gb2312'
    soup = BeautifulSoup(resp.text,'lxml')
    resultList = soup.find(id="resultList")
    infos = resultList.find_all(class_='el')
    for info in infos:
        t1 = info.find(class_='t1').text.strip()
        t2 = info.find(class_='t2').text.strip()
        t3 = info.find(class_='t3').text.strip()
        t4 = info.find(class_='t4').text.strip()
        t5 = info.find(class_='t5').text.strip()
        format_str = '{0}\t{1}\t{2}\t{3}\t{4}'.format(t1,t2,t3,t4,t5)
#        print(format_str)
        info_list.append(format_str)

if __name__=='__main__':
    for i in range(1,pages+1):
        url = 'https://search.51job.com/list/030000%252C00,000000,0000,00,9,99,python,2,'+str(i)+'.html'
        print('\r当前进度:{0}/{1}'.format(i,pages),end = '')
        get_info(url)
        time.sleep(0.2)
    with open('F:/前程无忧广东省python.txt','w',encoding='utf8') as f:
        f.write('\n'.join(info_list))
    print('爬取结束!')
    
        



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

D_ry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值