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 ...
随机推荐
- 前端-css-长期维护
############### CSS简介 ################ # CSS # HTML是骨架 # CSS是样式 # JS是动作 # css和html是分成两个文件编写的,这 ...
- ionic3懒加载IonicPage使用报错
ionic3.X版本有不少亮点.作为从angular1到ionic1.ionic2一直用它们开发单页面应用的使用者来说,一直存在的一个痛点就是,将整个项目作为网页不打包成app的话,第一次加载时间太长 ...
- caffe之mac下环境搭建
参考 http://www.linuxidc.com/Linux/2016-09/135026.html 1. 安装brew,也叫homebrew,mac下类似于ubuntu的apt-get功能 cu ...
- MySQL性能优化最佳实践 - 05 MySQL核心参数优化
back_log参数的作用 指定MySQL可能的TCP/IP的连接数量(一个TCP/IP连接占256k),默认是50.当MySQL主线程在很短的时间内得到非常多的连接请求,该参数就起作用,之后主线程花 ...
- mysql表关系
表与表之间的关系 """ 把所有数据都存放于一张表的弊端 1.组织结构不清晰 2.浪费硬盘空间 3.扩展性极差 """ # 上述的弊端产生原 ...
- JAVA学习大纲
1.第一节 JAVA概念与JDK的安装 (1)JDK的安装和环境变量的设置: (2)相关基本概念:JDK.SDK.JRE.JVM.J2SE.J2EE.J2ME.java API.JAVA语言特点: ( ...
- http概述——http笔记一
之前想深入的了解学习下HTTP,所以就买了本砖头<HTTP权威指南>.最近一直在看,可是发现看书只有输入并没有输出,不行.所以就打算把自己的理解写成一系列的笔记,供以后翻阅. 大概画了张本 ...
- Center Loss - A Discriminative Feature Learning Approach for Deep Face Recognition
URL:http://ydwen.github.io/papers/WenECCV16.pdf这篇论文主要的贡献就是提出了Center Loss的损失函数,利用Softmax Loss和Center ...
- install jekyll
最直接的方法就是运行快速指南中的命令: gem install jekyll 这个时候会提示: Command 'gem' not found, but can be installed with: ...
- flutter 入门(Mac)
背景 近一年时间都在用 React Native 开发公司的 APP,水平基本上可以说是登堂入室了.前一段时间兴起一阵 Flutter 热,后端的同事都有推荐,今年 Google 大会又推出 flut ...