换坑季-51Job前程无忧 Python爬虫

2023-11-11 07:10

本文主要是介绍换坑季-51Job前程无忧 Python爬虫,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

写了个简易的Python爬虫,实现对目的工作的分析。
说明,只用了正则re库进行数据处理,requests进行请求,开了4个简易的函数线程。
url是以下界面的url:
在这里插入图片描述
主要实现了以下CSV功能:
在这里插入图片描述
全部代码:

import requests
import re
import csv
from threading import Threaddef req(i):count = 1try:for url in i:headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'}response = requests.get(url=url, headers=headers, timeout=5)response.encoding = 'GBK'content = re.findall(r'<a target="_blank" title="(.*?)" href="(.*?)" onmousedown="">.*?<span class="t2"><a target="_blank" title="(.*?)" href=".*?">.*?</a></span>.*?<span class="t3">(.*?)</span>.*?<span class="t4">(.*?)</span>.*?<span class="t5">(.*?)</span>', response.text, re.S)# print(content)for index in content:txt = []title = index[0]thisUrl = index[1]try:thisContent = requests.get(url=thisUrl, headers=headers, timeout=5)text = re.findall(r'<div class="bmsg job_msg inbox">(.*?)<div class="mt10">', thisContent.text, re.S)final = ''.join(text).replace('\r\n\t\t\t\t\t\t', '').replace('<p>', '').replace('</p>', '').replace('<span>', '').replace('</span>', '').replace('<br>', '').replace('&nbsp;', '').replace('</div>', '').replace('<div>', '').replace('\t\t\t\t\t\t\t\t\t\t\t\t', '').replace('<b>', '').replace('</b>', '').replace('</li>', '').replace('</strong>', '').replace('<strong>', '').replace('<li>', '')company = index[2]area = index[3]salary = index[4]date = index[5]txt.append(title)txt.append(thisUrl)txt.append(final)txt.append(company)txt.append(area)txt.append(salary)txt.append(date)# print(txt)with open(r'./前程无忧.csv', 'a', newline='', encoding='utf-8-sig') as csvf:spanwriter = csv.writer(csvf)spanwriter.writerow(txt)count = count + 1except:print("此次请求详情失败!!!" + thisUrl)except:print('请求首页失败!' + i)print("共%d多少条信息~" % count)if __name__ == '__main__':txt1 = []txt2 = []txt3 = []txt4 = []url = 'https://search.51job.com/list/090200,000000,0000,00,9,99,%25E8%25BF%2590%25E7%25BB%25B4%25E5%25B7%25A5%25E7%25A8%258B%25E5%25B8%2588,2,{}.html?lang=c&stype=1&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare='for i in range(1, 6):i = url.format(i)txt1.append(i)for j in range(6, 12):j = url.format(j)txt2.append(j)for k in range(12, 18):k = url.format(k)txt3.append(k)for k in range(18, 24):k = url.format(k)txt3.append(k)t1 = Thread(target=req, args=(txt1,))t1.start()print('t1线程开始!')t2 = Thread(target=req, args=(txt2,))t2.start()print('t2线程开始!')t3 = Thread(target=req, args=(txt3,))t3.start()print('t3线程开始!')t4 = Thread(target=req, args=(txt4,))t4.start()print('t4线程开始!')

上面这个开了4个线程的代码其实对爬虫还是不太友好。
以下代码可以在详细页进行爬虫,建议使用生产者消费者模式。

import re
import requestsurl = 'https://jobs.51job.com/chengdu-jjq/114069603.html?s=01&t=0'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'}
response = requests.get(url=url, headers=headers, timeout=5)
response.encoding = 'GBK'
# 工作职位
job = re.findall(r'<h1 title="(.*?)">', response.text)
print(job)
# 薪资
salary = re.findall(r'<h1 title=".*?">.*?<input value="\d+" name="hidJobID" id="hidJobID" type="hidden" jt="0">.*?<strong>(.*?)</strong>', response.text, re.S)
print(salary)
# 公司名称
company = re.findall(r'target="_blank" title="(.*?)" class="catn">', response.text)
print(company)
# 公司性质
flag = re.findall(r'<p class="at" title="(.*?)"><span class="i_flag"></span>.*?</p>', response.text)
print(flag)
# 公司规模
people = re.findall(r'<p class="at" title="(.*?)"><span class="i_people"></span>.*?</p>', response.text)
print(people)
# 职位详细的内容:
content = re.findall(r'<p class="msg ltype" title="(.*?)">.*?</p>', response.text, re.S)
# 将正则匹配的内容进行字符串处理
content_str = ''.join(content)
# 城市
txt_city = re.findall(r'.*?(成都.*?)&nbsp.*?', content_str)
print(txt_city)
# 招多少人
txt_count = re.findall(r'.*?(招\d人).*?', content_str)
print(txt_count)
# 经验
txt_experience = re.findall(r'.*?(无工作经验).*?', content_str)
if len(txt_experience) == 0:txt_experience = re.findall(r'.*?(\d+年经验).*?', content_str)
print(txt_experience)
# 发布日期
txt_date = re.findall(r'.*?(\d+-\d+发布).*?', content_str)
print(txt_date)
# 学历要求, 只匹配了大专和本科
txt_education = re.findall(r'.*?(本科).*?', content_str)
if len(txt_education) == 0:txt_education = re.findall(r'.*?(大专).*?', content_str)
else:txt_education = '无学历要求'
print(txt_education)
# 职位招聘要求内容描述:
descrition = re.findall(r'<div class="bmsg job_msg inbox">(.*?)<div class="mt10">', response.text, re.S)
descrition = ''.join(descrition).replace('\r\n\t\t\t\t\t\t', '').replace('<p>', '').replace('</p>', '').replace('<span>', '').replace('</span>', '').replace('<br>', '').replace('&nbsp;', '').replace('</div>', '').replace('<div>', '').replace('\t\t\t\t\t\t\t\t\t\t\t\t', '').replace('<b>', '').replace('</b>', '').replace('</li>', '').replace('</strong>', '').replace('<strong>', '').replace('<li>', '')
print(descrition)

这篇关于换坑季-51Job前程无忧 Python爬虫的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/388383

相关文章

基于Python开发Windows屏幕控制工具

《基于Python开发Windows屏幕控制工具》在数字化办公时代,屏幕管理已成为提升工作效率和保护眼睛健康的重要环节,本文将分享一个基于Python和PySide6开发的Windows屏幕控制工具,... 目录概述功能亮点界面展示实现步骤详解1. 环境准备2. 亮度控制模块3. 息屏功能实现4. 息屏时间

Python如何去除图片干扰代码示例

《Python如何去除图片干扰代码示例》图片降噪是一个广泛应用于图像处理的技术,可以提高图像质量和相关应用的效果,:本文主要介绍Python如何去除图片干扰的相关资料,文中通过代码介绍的非常详细,... 目录一、噪声去除1. 高斯噪声(像素值正态分布扰动)2. 椒盐噪声(随机黑白像素点)3. 复杂噪声(如伪

Python中图片与PDF识别文本(OCR)的全面指南

《Python中图片与PDF识别文本(OCR)的全面指南》在数据爆炸时代,80%的企业数据以非结构化形式存在,其中PDF和图像是最主要的载体,本文将深入探索Python中OCR技术如何将这些数字纸张转... 目录一、OCR技术核心原理二、python图像识别四大工具库1. Pytesseract - 经典O

基于Linux的ffmpeg python的关键帧抽取

《基于Linux的ffmpegpython的关键帧抽取》本文主要介绍了基于Linux的ffmpegpython的关键帧抽取,实现以按帧或时间间隔抽取关键帧,文中通过示例代码介绍的非常详细,对大家的学... 目录1.FFmpeg的环境配置1) 创建一个虚拟环境envjavascript2) ffmpeg-py

python使用库爬取m3u8文件的示例

《python使用库爬取m3u8文件的示例》本文主要介绍了python使用库爬取m3u8文件的示例,可以使用requests、m3u8、ffmpeg等库,实现获取、解析、下载视频片段并合并等步骤,具有... 目录一、准备工作二、获取m3u8文件内容三、解析m3u8文件四、下载视频片段五、合并视频片段六、错误

Python中提取文件名扩展名的多种方法实现

《Python中提取文件名扩展名的多种方法实现》在Python编程中,经常会遇到需要从文件名中提取扩展名的场景,Python提供了多种方法来实现这一功能,不同方法适用于不同的场景和需求,包括os.pa... 目录技术背景实现步骤方法一:使用os.path.splitext方法二:使用pathlib模块方法三

Python打印对象所有属性和值的方法小结

《Python打印对象所有属性和值的方法小结》在Python开发过程中,调试代码时经常需要查看对象的当前状态,也就是对象的所有属性和对应的值,然而,Python并没有像PHP的print_r那样直接提... 目录python中打印对象所有属性和值的方法实现步骤1. 使用vars()和pprint()2. 使

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

一文深入详解Python的secrets模块

《一文深入详解Python的secrets模块》在构建涉及用户身份认证、权限管理、加密通信等系统时,开发者最不能忽视的一个问题就是“安全性”,Python在3.6版本中引入了专门面向安全用途的secr... 目录引言一、背景与动机:为什么需要 secrets 模块?二、secrets 模块的核心功能1. 基

python常见环境管理工具超全解析

《python常见环境管理工具超全解析》在Python开发中,管理多个项目及其依赖项通常是一个挑战,下面:本文主要介绍python常见环境管理工具的相关资料,文中通过代码介绍的非常详细,需要的朋友... 目录1. conda2. pip3. uvuv 工具自动创建和管理环境的特点4. setup.py5.