侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

利用python如何在前程无忧高效投递简历

Python  /  管理员 发布于 7年前   169

前言

在前程无忧上投递简历发现有竞争力分析,免费能看到匹配度评价和综合竞争力分数,可以做投递参考

计算方式

综合竞争力得分应该越高越好,匹配度评语也应该评价越高越好

抓取所有职位关键字搜索结果并获取综合竞争力得分和匹配度评语,最后筛选得分评语自动投递合适的简历

登陆获取cookie

from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()# chrome_options.add_argument('--headless')from time import sleepimport refrom lxml import etreeimport requestsimport osimport jsondriver = webdriver.Chrome(chrome_options=chrome_options,executable_path = 'D:\python\chromedriver.exe')headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}driver.get(https://search.51job.com/list/020000,000000,0000,00,9,99,%2520,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=)

webdriver需要在相应域名写入cookie,所以转到职位搜索页面

def get_cookie():  driver.get("https://login.51job.com/login.php?loginway=1&lang=c&url=")  sleep(2)  phone=input("输入手机号:")  driver.find_element_by_id("loginname").send_keys(phone)  driver.find_element_by_id("btn7").click()  sleep(1)  code=input("输入短信:")  driver.find_element_by_id("phonecode").send_keys(code)  driver.find_element_by_id("login_btn").click()  sleep(2)  cookies = driver.get_cookies()  with open("cookie.json", "w")as f:    f.write(json.dumps(cookies))

检查cookie文件是否存在,如果不存在执行get_cookie把cookie写入文件,在登陆的时候最好不用无头模式,偶尔有滑动验证码

前程无忧手机短信一天只能发送三条,保存cookie下次登陆用

def get_job():  driver.get("https://search.51job.com/list/020000,000000,0000,00,9,99,%2520,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=")  sleep(2)  job=input("输入职位:")  driver.find_element_by_id("kwdselectid").send_keys(job)  driver.find_element_by_xpath('//button[@class="p_but"]').click()  url=driver.current_url  page=driver.page_source  return url,page

在职位搜索获取职位搜索结果,需要返回页面源码和地址

分析页码结构html前的是页码,全部页码数量通过共XX页得到

def get_pages(url,page):  tree=etree.HTML(page)  href=[]  x = tree.xpath('//span[@class="td"]/text()')[0]  total_page=int(re.findall("(\d+)", x)[0])  for i in range(1,total_page+1):    href.append(re.sub("\d.html", f'{i}.html', url))  return href

获取全部页码

def get_job_code(url):  headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}  r=session.get(url,headers=headers)  tree=etree.HTML(r.text)  divs=tree.xpath('//div[@class="el"]/p/span/a/@href')  job=str(divs)  job_id=re.findall("\/(\d+).html",job)  return job_id

获取职位id

修改id请求网址到竞争力分析页面

def get_info(job_id):  href=f"https://i.51job.com/userset/bounce_window_redirect.php?jobid={job_id}&redirect_type=2"  r=session.get(href,headers=headers)  r.encoding=r.apparent_encoding  tree=etree.HTML(r.text)  pingjia=tree.xpath('//div[@class="warn w1"]//text()')[0].strip()  gongsi=[]  for i in tree.xpath('//div[@class="lf"]//text()'):    if i.strip():      gongsi.append(i.strip())  fenshu=[]  for i in tree.xpath('//ul[@class="rt"]//text()'):    if i.strip():      fenshu.append(i.strip())  url=f"https://jobs.51job.com/shanghai/{job_id}.html?s=03&t=0"  return {"公司":gongsi[1],"职位":gongsi[0],"匹配度":pingjia,fenshu[3]:fenshu[2],"链接":url,"_id":job_id}

抓取竞争力分析页面,返回一个字典

主程序

if not os.path.exists("cookie.json"):    get_cookie()f=open("cookie.json","r")cookies=json.loads(f.read())f.close()

检查cookie文件载入cookie,不存在执行get_cookie()把cookie保存到文件

session = requests.Session()  for cookie in cookies:   driver.add_cookie(cookie)session.cookies.set(cookie['name'],cookie['value'])url, page = get_job()driver.close()

在session和webdriver写入cookie登陆

获取第一页和url后webdriver就可以关掉了

code=[]for i in get_pages(url,page):  code=code+get_job_code(i)

获取的职位id添加到列表

import pymongoclient=pymongo.MongoClient("localhost",27017)db=client["job_he"]job_info=db["job_info"]for i in code:  try:    if not job_info.find_one({"_id":i}):      info=get_info(i)      sleep(1)      job_info.insert_one(info)      print(info,"插入成功")  except:    print(code)

龟速爬取,用MongDB保存结果,职位id作为索引id,插入之前检查id是否存在简单去重减少访问

吃完饭已经抓到8000个职位了,筛选找到127个匹配度好的,开始批量投递

登陆状态点击申请职位,用wevdriver做

for i in job_info.find({"匹配度":{$regex:"排名很好"},"综合竞争力得分":{$gte:"80"}}):  print(i)  try:    driver.get(i)    driver.find_element_by_id("app_ck").click()    sleep(2)  except:    pass

用cookie登陆简单for循环投递,在Mongodb里查表,正则筛选匹配度和竞争力得分获取所有匹配结果

投递成功

代码

from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()# chrome_options.add_argument('--headless')from time import sleepimport refrom lxml import etreeimport requestsimport osimport jsondriver = webdriver.Chrome(chrome_options=chrome_options,executable_path = 'D:\python\chromedriver.exe')headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}driver.get("https://search.51job.com/list/020000,000000,0000,00,9,99,%2520,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=")def get_cookie():  driver.get("https://login.51job.com/login.php?loginway=1&lang=c&url=")  sleep(2)  phone=input("输入手机号:")  driver.find_element_by_id("loginname").send_keys(phone)  driver.find_element_by_id("btn7").click()  sleep(1)  code=input("输入短信:")  driver.find_element_by_id("phonecode").send_keys(code)  driver.find_element_by_id("login_btn").click()  sleep(2)  cookies = driver.get_cookies()  with open("cookie.json", "w")as f:    f.write(json.dumps(cookies))def get_job():  driver.get("https://search.51job.com/list/020000,000000,0000,00,9,99,%2520,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=")  sleep(2)  job=input("输入职位:")  driver.find_element_by_id("kwdselectid").send_keys(job)  driver.find_element_by_xpath('//button[@class="p_but"]').click()  url=driver.current_url  page=driver.page_source  return url,pagedef close_driver():  driver.close()def get_pages(url,page):  tree=etree.HTML(page)  href=[]  x = tree.xpath('//span[@class="td"]/text()')[0]  total_page=int(re.findall("(\d+)", x)[0])  for i in range(1,total_page+1):    href.append(re.sub("\d.html", f'{i}.html', url))  return hrefdef get_job_code(url):  headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}  r=session.get(url,headers=headers)  tree=etree.HTML(r.text)  divs=tree.xpath('//div[@class="el"]/p/span/a/@href')  job=str(divs)  job_id=re.findall("\/(\d+).html",job)  return job_iddef get_info(job_id):  href=f"https://i.51job.com/userset/bounce_window_redirect.php?jobid={job_id}&redirect_type=2"  r=session.get(href,headers=headers)  r.encoding=r.apparent_encoding  tree=etree.HTML(r.text)  pingjia=tree.xpath('//div[@class="warn w1"]//text()')[0].strip()  gongsi=[]  for i in tree.xpath('//div[@class="lf"]//text()'):    if i.strip():      gongsi.append(i.strip())  fenshu=[]  for i in tree.xpath('//ul[@class="rt"]//text()'):    if i.strip():      fenshu.append(i.strip())  url=f"https://jobs.51job.com/shanghai/{job_id}.html?s=03&t=0"  return {"公司":gongsi[1],"职位":gongsi[0],"匹配度":pingjia,fenshu[3]:fenshu[2],"链接":url,"_id":job_id}if not os.path.exists("cookie.json"):  get_cookie()f=open("cookie.json","r")cookies=json.loads(f.read())f.close()session = requests.Session()for cookie in cookies:  driver.add_cookie(cookie)  session.cookies.set(cookie['name'], cookie['value'])url, page = get_job()driver.close()code=[]for i in get_pages(url,page):  code=code+get_job_code(i)import pymongoclient=pymongo.MongoClient("localhost",27017)db=client["job_he"]job_info=db["job_info"]for i in code:  try:    if not job_info.find_one({"_id":i}):      info=get_info(i)      sleep(1)      job_info.insert_one(info)      print(info)      print("插入成功")  except:    print(code)

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家的支持。


  • 上一条:
    深入浅析Python 中 is 语法带来的误解
    下一条:
    Python可迭代对象操作示例
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在python语言中Flask框架的学习及简单功能示例(0个评论)
    • 在Python语言中实现GUI全屏倒计时代码示例(0个评论)
    • Python + zipfile库实现zip文件解压自动化脚本示例(0个评论)
    • python爬虫BeautifulSoup快速抓取网站图片(1个评论)
    • vscode 配置 python3开发环境的方法(0个评论)
    • 近期文章
    • 在windows10中升级go版本至1.24后LiteIDE的Ctrl+左击无法跳转问题解决方案(0个评论)
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2018-04
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2022-01
    • 2023-07
    • 2023-10
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客