换坑季-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和Tkinter创建一个功能完整的Windows风格计算器程序,包括基本运算、高级科学计算(如三... 目录python实现Windows系统计算器程序(含高级功能)1. 使用Tkinter实现基础计算器2.

Python开发文字版随机事件游戏的项目实例

《Python开发文字版随机事件游戏的项目实例》随机事件游戏是一种通过生成不可预测的事件来增强游戏体验的类型,在这篇博文中,我们将使用Python开发一款文字版随机事件游戏,通过这个项目,读者不仅能够... 目录项目概述2.1 游戏概念2.2 游戏特色2.3 目标玩家群体技术选择与环境准备3.1 开发环境3

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

基于Python打造一个智能单词管理神器

《基于Python打造一个智能单词管理神器》这篇文章主要为大家详细介绍了如何使用Python打造一个智能单词管理神器,从查询到导出的一站式解决,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 项目概述:为什么需要这个工具2. 环境搭建与快速入门2.1 环境要求2.2 首次运行配置3. 核心功能使用指

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

Python中pywin32 常用窗口操作的实现

《Python中pywin32常用窗口操作的实现》本文主要介绍了Python中pywin32常用窗口操作的实现,pywin32主要的作用是供Python开发者快速调用WindowsAPI的一个... 目录获取窗口句柄获取最前端窗口句柄获取指定坐标处的窗口根据窗口的完整标题匹配获取句柄根据窗口的类别匹配获取句

利用Python打造一个Excel记账模板

《利用Python打造一个Excel记账模板》这篇文章主要为大家详细介绍了如何使用Python打造一个超实用的Excel记账模板,可以帮助大家高效管理财务,迈向财富自由之路,感兴趣的小伙伴快跟随小编一... 目录设置预算百分比超支标红预警记账模板功能介绍基础记账预算管理可视化分析摸鱼时间理财法碎片时间利用财