selenium 爬boss
# 有问题 from selenium import webdriver
import time
from lxml import etree class LagouSpider(object):
driver_path = r"G:\Crawler and Data\chromedriver.exe" def __init__(self):
self.driver = webdriver.Chrome(executable_path=self.driver_path)
self.url = "https://www.zhipin.com/job_detail/?query=python&city=101010100&industry=&position="
self.positions = []
self.position_dict = {}
self.detail_url_list = []
def run(self):
# 访问首页
self.driver.get(self.url)
# 获取页面信息
# page_source可以获取页面的所有数据,包括每个职位的链接
source= self.driver.page_source
self.parse_list_page(source) def parse_list_page(self,source):
# 每个职位的链接
tree = etree.HTML(source) # 获取职位的链接 ******
li_list = tree.xpath("//div[@class='job-box']/div[@class='job-list']/ul/li")
for li in li_list:
detail_url = li.xpath('.//div[@class="info-primary"]/h3/a/@href')[0]
detail_url = "https://www.zhipin.com"+detail_url
print(detail_url)
self.detail_url_list.append(detail_url)
title = li.xpath('.//div[@class="info-primary"]/h3/a/div[@class="job-title"]/text()')[0]
salary = li.xpath('.//div[@class="info-primary"]/h3/a/span[@class="red"]/text()')[0]
company = li.xpath('.//div[@class="info-company"]//h3/a/text()')[0]
self.position_dict["title"]=title
self.position_dict["salary"]=salary
self.position_dict["company"]=company self.detail_page(detail_url)
# break def detail_page(self,url):
for url in self.detail_url_list:
# self.driver.get(url) # 直接访问这个url
self.driver.execute_script('window.open("%s")'%url) # 新打开一个窗口
self.driver.switch_to.window(self.driver.window_handles[1]) # 切换到新窗口
source = self.driver.page_source
tree = etree.HTML(source)
desc = tree.xpath("//div[@id='main']/div[3]/div/div[2]/div[2]/div[1]/div")
# 获取一个标签(含有其他标签)下所有的文本
desc_text = desc[0].xpath('string()').strip()
self.position_dict['desc_text'] = desc_text
print(self.position_dict)
time.sleep(2)
self.driver.close() # 关闭页面
self.driver.switch_to.window(self.driver.window_handles[0]) # 切换到新窗口 if __name__ == '__main__':
spider = LagouSpider()
spider.run()
selenium 爬boss的更多相关文章
- Java+selenium 爬Boss直聘中职位信息,薪资水平和职位描述
需要下载合适的selenium webdirver jar包和对应浏览器的驱动jar包 import org.openqa.selenium.By; import org.openqa.selen ...
- [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)
转载自:http://blog.csdn.net/eastmount/article/details/51231852 一. 文章介绍 源码下载地址:http://download.csdn.net/ ...
- selenium爬取煎蛋网
selenium爬取煎蛋网 直接上代码 from selenium import webdriver from selenium.webdriver.support.ui import WebDriv ...
- 利用selenium爬取京东商品信息存放到mongodb
利用selenium爬取京东商城的商品信息思路: 1.首先进入京东的搜索页面,分析搜索页面信息可以得到路由结构 2.根据页面信息可以看到京东在搜索页面使用了懒加载,所以为了解决这个问题,使用递归.等待 ...
- 利用Selenium爬取淘宝商品信息
一. Selenium和PhantomJS介绍 Selenium是一个用于Web应用程序测试的工具,Selenium直接运行在浏览器中,就像真正的用户在操作一样.由于这个性质,Selenium也是一 ...
- Scrapy 框架 使用 selenium 爬取动态加载内容
使用 selenium 爬取动态加载内容 开启中间件 DOWNLOADER_MIDDLEWARES = { 'wangyiPro.middlewares.WangyiproDownloaderMidd ...
- 使用selenium爬取网站动态数据
处理页面动态加载的爬取 selenium selenium是python的一个第三方库,可以实现让浏览器完成自动化的操作,比如说点击按钮拖动滚轮等 环境搭建: 安装:pip install selen ...
- scrapy框架 + selenium 爬取豆瓣电影top250......
废话不说,直接上代码..... 目录结构 items.py import scrapy class DoubanCrawlerItem(scrapy.Item): # 电影名称 movieName = ...
- 爬虫学习06用selenium爬取空间
用selenium爬取空间 from selenium import webdriver from lxml import etree import time pro = webdriver.Chro ...
随机推荐
- 学习python-20191107
一.导入模块的两种方式 方式1:import 包名.模块名 [ as 别名]方式2:from 包名 import 模块名 from 包名.模块名 import 变量|函数|类 # ...
- nowcoder-548C-Tachibana Kanade Loves Review
链接:https://ac.nowcoder.com/acm/contest/548/C来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言10485 ...
- MyBatis注解及动态Sql
一.注解实现MyBatis配置 java注解是在jdk1.5版本之后开始加入的,不得不说注解对于我们开发人员来说是个很方便的东西,实现起来也非常的简单,下边我们说一下在MyBatis中使用注解来替换M ...
- struts2 标签s:select在table中单行显示
<table class="query_form_table"> <tr> <th>用户 ...
- mysqli存储过程
<?php$link = mysqli_connect('localhost','root','','chinatupai'); $sql = "call getEmail('000 ...
- 二评北科团委:“斩首计划”进行时,其用心也毒
近日,在同学们和热心群众的共同努力下,各高校相继悬崖勒马,北大马会.北语新新青年.人大新光等进步社团均顺利注册.而北科团委倒行逆施,可谓一枝独秀,对于齐民学社的同学们的诉求,不仅不予以回应,反而采取表 ...
- 详解js面向对象编程
转自:http://segmentfault.com/a/1190000000713346 基本概念 ECMA关于对象的定义是:”无序属性的集合,其属性可以包含基本值.对象或者函数.“对象的每个属性或 ...
- 操作的系统的PV操作
转自:https://blog.csdn.net/sunlovefly2012/article/details/9396201 在操作系统中,进程之间经常会存在互斥(都需要共享独占性资源时) 和同步( ...
- 数据库三大范式和反范式 · oldmee
后一个范式都是在满足前一个范式的基础上建立的. 1NF 无重复的列.表中的每一列都是不可分割的基本数据项.不满足1NF的数据库不是关系数据库.如联系人表(姓名,电话),一个联系人有家庭电话和公司电话, ...
- 用缓冲技术OSCache 提高JSP应用的性能和稳定性
一.概述 在Web应用中,有些报表的生成可能需要数据库花很长时间才能计算出来:有的网站提供天气信息,它需要访问远程服务器进行SOAP调用才能得到温度信息.所有这一切都属于复杂信息的例子.在Web页面中 ...