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


Posted in Python onMay 07, 2019

前言

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

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

计算方式

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

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

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

登陆获取cookie

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
# chrome_options.add_argument('--headless')
from time import sleep
import re
from lxml import etree
import requests
import os
import json

driver = 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,所以转到职位搜索页面

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

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

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

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

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

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

分析页码结构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

获取全部页码

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

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

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

修改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}

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

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

主程序

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 pymongo
client=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是否存在简单去重减少访问

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

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

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

登陆状态点击申请职位,用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里查表,正则筛选匹配度和竞争力得分获取所有匹配结果

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

投递成功

代码

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
# chrome_options.add_argument('--headless')
from time import sleep
import re
from lxml import etree
import requests
import os
import json

driver = 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,page

def 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 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

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()
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 pymongo
client=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 相关文章推荐
在Linux下使用Python的matplotlib绘制数据图的教程
Jun 11 Python
Python实现telnet服务器的方法
Jul 10 Python
Python将阿拉伯数字转换为罗马数字的方法
Jul 10 Python
玩转python爬虫之cookie使用方法
Feb 17 Python
Python 结巴分词实现关键词抽取分析
Oct 21 Python
python使用筛选法计算小于给定数字的所有素数
Mar 19 Python
利用Python yagmail三行代码实现发送邮件
May 11 Python
pandas DataFrame 删除重复的行的实现方法
Jan 29 Python
如何使用pycharm连接Databricks的步骤详解
Sep 23 Python
Python+unittest+requests+excel实现接口自动化测试框架
Dec 23 Python
用基于python的appium爬取b站直播消费记录
Apr 17 Python
手把手教你实现PyTorch的MNIST数据集
Jun 28 Python
Python可迭代对象操作示例
May 07 #Python
python实现支付宝转账接口
May 07 #Python
Python实现九宫格式的朋友圈功能内附“马云”朋友圈
May 07 #Python
python验证身份证信息实例代码
May 06 #Python
CentOS6.9 Python环境配置(python2.7、pip、virtualenv)
May 06 #Python
Python实现的栈、队列、文件目录遍历操作示例
May 06 #Python
Python两台电脑实现TCP通信的方法示例
May 06 #Python
You might like
定制404错误页面,并发信给管理员的程序
2006/10/09 PHP
基于Windows下Apache PHP5.3.1安装教程
2010/01/08 PHP
thinkPHP的Html模板标签使用方法
2012/11/13 PHP
PHP实现XML与数据格式进行转换类实例
2015/07/29 PHP
PHP共享内存用法实例分析
2016/02/12 PHP
在Mac OS下搭建LNMP开发环境的步骤详解
2017/03/10 PHP
cookie 最近浏览记录(中文escape转码)具体实现
2013/06/08 Javascript
Angularjs 基础入门
2014/12/26 Javascript
第十篇BootStrap轮播插件使用详解
2016/06/21 Javascript
学习Angularjs分页指令
2016/07/01 Javascript
jQuery弹出层插件popShow(改进版)用法示例
2017/01/23 Javascript
JS检测window.open打开的窗口是否关闭
2017/06/25 Javascript
浅谈vue-router2路由参数注意的问题
2017/11/08 Javascript
一次记住JavaScript的6个正则表达式方法
2018/02/22 Javascript
NodeJS模块与ES6模块系统语法及注意点详解
2019/01/04 NodeJs
python魔法方法-属性转换和类的表示详解
2016/07/22 Python
Python类属性的延迟计算
2016/10/22 Python
itchat接口使用示例
2017/10/23 Python
numpy中实现二维数组按照某列、某行排序的方法
2018/04/04 Python
python如何发布自已pip项目的方法步骤
2018/10/09 Python
Python读取系统文件夹内所有文件并统计数量的方法
2018/10/23 Python
基于python实现的百度音乐下载器python pyqt改进版(附代码)
2019/08/05 Python
Python字典推导式将cookie字符串转化为字典解析
2019/08/10 Python
python匿名函数lambda原理及实例解析
2020/02/07 Python
django 链接多个数据库 并使用原生sql实现
2020/03/28 Python
python怎么判断模块安装完成
2020/06/19 Python
Django如何批量创建Model
2020/09/01 Python
Python开发入门——迭代的基本使用
2020/09/03 Python
python如何快速拼接字符串
2020/10/28 Python
路政管理专业个人自荐信范文
2013/11/30 职场文书
经理秘书找工作求职信
2013/12/19 职场文书
教学质量评估实施方案
2014/03/17 职场文书
我的中国梦演讲稿300字
2014/08/19 职场文书
承诺书模板
2014/08/30 职场文书
优秀党员事迹材料
2014/12/18 职场文书
Java日常练习题,每天进步一点点(38)
2021/07/26 Java/Android