1、环境python2.7+selenium+PhantomJS(软件安装和库的安装网上都有教程我们跳过,so easy)

2、原理

绕过首页登录需要验证码,直接进入搜索栏,输入搜索的职位+地区搜索出职位列表,点击全选,选择该页的所有工作,当然培训的也选起了,未做筛选的工作,亲们可以加上,第一次提交不需要验证码,第二次提交就需要验证码了,手动输入,验证码输入用的raw_input,输入之后程序继续运行,往复操作,总的来说也不智能,需要修改的地方很多,就当大家了解下selenium+PhantomJS的功能。

3、贴上代码

#!/usr/bin/Python
# -*- coding: utf-8 -*-
import os
from selenium import webdriver
import urllib2
import time
from os import path
import image
d = path.dirname(__file__)
class Zhilian:
def __init__(self):
self.arr = []
print 1
def main(self, browser):
'''函数主体'''
try:
for v in browser.find_elements_by_class_name('newlist'):
job_name = v.find_element_by_class_name('zwmc').text
price = v.find_element_by_class_name('zwyx').text
print job_name+'-'+price
except:
print 'select error!!'
time.sleep(2)
###获取用户信息
user_name = browser.find_element_by_xpath('/html/body/div[1]/div[1]/div/div/div[1]').text
try:
user_name = browser.find_element_by_xpath('/html/body/div[1]/div[1]/div/div/div[1]').text
if user_name ==u'登录注册':
is_logined = 0
else:
is_logined = 1
except:
print 'head error!!'
try:
browser.find_element_by_xpath('//*[@id="checkbox4al2"]').click()
browser.find_element_by_xpath('//*[@id="newlist_list_div"]/p[1]/a[1]').click()
except:
print 'error'
time.sleep(2)
####第一次需要执行登录
print is_logined
test(browser)
if is_logined == 0:
try:
time.sleep(3)
####开始输入你的用户名和密码
name = raw_input('please input your zhilian user_name: ')
pwd = raw_input('Please input your zhilian password: ')
browser.find_element_by_xpath('//*[@id="simplaceholder"]').clear()
browser.find_element_by_xpath('//*[@id="simplaceholder"]').send_keys(name)
browser.find_element_by_xpath('//*[@id="loginBlock"]/form/ul/li[3]/label/input').clear()
browser.find_element_by_xpath('//*[@id="loginBlock"]/form/ul/li[3]/label/input').send_keys(pwd)
browser.find_element_by_xpath('//*[@id="submitBlock"]/div[1]/a').click()
print 'login success!!'
except:
print "login false or or this account is online!!"
time.sleep(3)
##第二次开始需要填入验证码
try:
if browser.find_element_by_xpath('//*[@id="validate"]'):
###开始截图
browser.get_screenshot_as_file(path.join(d,'1.png'))
###自动打开截图
####根绝截图输入验证码
os.system('start E:\\test\\zhilian\\1.png')
###开始输入验证码
code = raw_input('please input the code: ')
###将验证码放入输入框
browser.find_element_by_xpath('//*[@id="validate"]').clear()
browser.find_element_by_xpath('//*[@id="validate"]').send_keys(code)
browser.find_element_by_xpath('//*[@id="applynowbutton"]').click()
print 'apply success!!'
except:
print 'code error!!'
###开始查询下一页
print 'We can select next page!!'
next_page = browser.find_element_by_xpath('/html/body/div[3]/div[3]/div[3]/form/div[1]/div[1]/div[3]/ul/li[7]/a')
if next_page:
browser.find_element_by_xpath('/html/body/div[3]/div[3]/div[3]/form/div[1]/div[1]/div[3]/ul/li[7]/a').click()
self.main(browser) '''
try:
next_page = browser.find_element_by_xpath('/html/body/div[3]/div[3]/div[3]/form/div[1]/div[1]/div[3]/ul/li[7]/a')
if next_page:
self.main(city,job,page)
except:
print 'this is the last page!!'
'''
def check():
job = raw_input('please input the job name which you want to select: ')
city = raw_input('please input the city name which you want to select: ')
answer = raw_input('Do you sure the city name is "'+city+'" and the job name is "'+job+'", please input yes or no to check: ')
if answer =='yes':
###确认无误
list = []
list.append(city)
list.append(job)
else:
check()
if list:
return list def test(browser):
'''测试函数'''
###开始截图
browser.get_screenshot_as_file(path.join(d,'1.png'))
###自动打开截图
####根绝截图输入验证码
os.system('start E:\\test\\zhilian\\1.png') if __name__ == '__main__':
zhilian = Zhilian()
###设置关键字
list = check()
page=1
city = list[0].decode('gbk')
job = list[1].decode('gbk')
browser = webdriver.PhantomJS('E:\\p_python\\Scripts\\phantomjs\\bin\\phantomjs.exe')
#browser.get('http://www.baidu.com')
browser.get('http://sou.zhaopin.com/jobs/searchresult.ashx')
time.sleep(3)
####开始模拟搜索条件
try:
browser.find_element_by_xpath('//*[@id="KeyWord_kw2"]').clear()
browser.find_element_by_xpath('//*[@id="KeyWord_kw2"]').send_keys(job)
browser.find_element_by_xpath('//*[@id="JobLocation"]').clear()
browser.find_element_by_xpath('//*[@id="JobLocation"]').send_keys(city)
browser.find_element_by_xpath('//*[@id="searchForm"]/form/div[6]/button').click()
except:
print 'input select_info error!!'
time.sleep(2)
zhilian.main(browser)
#test()

python+selenium+PhantomJS批量投递智联简历(不要用自己的账号进行测试,请使用小号,很烦人的,哈哈哈)的更多相关文章

  1. Python + Selenium +Chrome 批量下载网页代码修改【新手必学】

    Python + Selenium +Chrome 批量下载网页代码修改主要修改以下代码可以调用 本地的 user-agent.txt 和 cookie.txt来达到在登陆状态下 批量打开并下载网页, ...

  2. python selenium+phantomjs alert()弹窗报错

    问题:用selenium+phantomjs 模拟登陆,网页用JavaScript的alert("登陆成功")弹出框,但是用switch_to_alert().accept()报错 ...

  3. python+selenium+PhantomJS爬取网页动态加载内容

    一般我们使用python的第三方库requests及框架scrapy来爬取网上的资源,但是设计javascript渲染的页面却不能抓取,此时,我们使用web自动化测试化工具Selenium+无界面浏览 ...

  4. 看我怎么扒掉CSDN首页的底裤(python selenium+phantomjs爬取CSDN首页内容)

    这里只是学习一下动态加载页面内容的抓取,并不适用于所有的页面. 使用到的工具就是python selenium和phantomjs,另外调试的时候还用了firefox的geckodriver.exe. ...

  5. python + selenium + PhantomJS 获取腾讯应用宝APP评论

    PhantomJS PhantomJS 是一个基于WebKit的服务器端JavaScript API,它无需浏览器的支持即可实现对Web的支持,且原生支持各种Web标准,如DOM 处理.JavaScr ...

  6. 基于Python, Selenium, Phantomjs无头浏览器访问页面

    引言: 在自动化测试以及爬虫领域,无头浏览器的应用场景非常广泛,本文将梳理其中的若干概念和思路,并基于代码示例其中的若干使用技巧. 1. 无头浏览器 通常大家在在打开网页的工具就是浏览器,通过界面上输 ...

  7. python+Selenium PhantomJS网页截图

    PhantomJS是一个基于webkit的JavaScript API.它使用QtWebKit作为它核心浏览器的功能,使用webkit来编译解释执行JavaScript代码.任何你可以在基于webki ...

  8. Python+Selenium+PhantomJS下载JavaScript异步加载网页

    # -*- coding: utf-8 -*- from selenium import webdriver import selenium.webdriver.support.ui as ui fr ...

  9. Python Selenium + phantomJS 模拟登陆教务管理系统 “抢课”

    # _*_coding:utf-8_*_ from selenium import webdriver from selenium.webdriver.common.action_chains imp ...

随机推荐

  1. Java参数验证Bean Validation 框架

    1.为什么要做参数校验? 参数校验和业务逻辑代码分离,参数校验代码复用,统一参数校验方式.校验不太通过时统一异常描述. 2.bean validation规范 JSR303 规范(Bean Valid ...

  2. ML(附录3)——过拟合与欠拟合

    过拟合与欠拟合 我们希望机器学习得到好的模型,该模型能够从训练样本中找到一个能够适应潜在样本的普遍规律.然而,如果机器学习学的“太好”了,以至把样本的自身特点当作潜在样本的一般特性,这就使得模型的泛化 ...

  3. mysql之 表数据存放路径非datadir目录

    假如,新建一张表,并让该表的存储路径 不是默认的/path/to/datadir/dbname .而是 指定存储的位置 应该如何处理? 方法一shell> mkdir /Generalt1she ...

  4. java自动装箱的一个例子

    Object obj = 56; int i = (Integer)obj; 第一行等价于: Object obj = Integer.valueOf(56);      Integer.valueO ...

  5. 记录一次linux删除mysql

    service mysqld status service mysqld stop ps –ef | grep mysql perl-DBD-MySQL-4.013-3.el6.x86_64 //删除 ...

  6. MySQL 快速构造一亿条记录的表

    在上一次朋友问我如何快速构造一亿条记录的表后,我理出了实行的办法,见:http://blog.csdn.net/mchdba/article/details/52938114,但是因为录入一亿表需要2 ...

  7. Hiero_FnNukeShotExporter的解析与修改

    研究对象:Hiero中的FnNukeShotExporter脚本 研究目的:修改FnNukeShotExporter使得可以将多个TrackItem导入到一个.nk中   FnNukeShotExpo ...

  8. 查看耗时长,CPU 100% 的SQL

    [session_id], [request_id], [start_time] AS '开始时间', [status] AS '状态', [command] AS '命令', dest.[text] ...

  9. 黄聪:JQUERY的datatables插件,Date range filter时间段筛选功能

    需配合moment插件实现:http://momentjs.com/ 演示:http://live.datatables.net/zuciyawi/1/edit HTML代码 <!DOCTYPE ...

  10. Python单元测试框架之pytest 2 -- 生成测试报告

    From: https://www.cnblogs.com/fnng/p/4768239.html Python单元测试框架之pytest -- 生成测试报告 2015-08-29 00:40 by ...