利用Crawlspider爬取腾讯招聘数据(全站,深度)
需求:
使用crawlSpider(全站)进行数据爬取
- 首页: 岗位名称,岗位类别
- 详情页:岗位职责
- 持久化存储
代码:
爬虫文件:
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from ..items import CrawlproItem,TenproItem_detail class CrawSpider(CrawlSpider):
name = 'craw'
# allowed_domains = ['www.xxx.com']
start_urls = ['https://hr.tencent.com/position.php?&start=0#a']
# 首页所有页码的连接提取器
link1 = LinkExtractor(allow=r'&start=\d+#a')
# 详情页连接提取器
link2 = LinkExtractor(allow=r'position_detail.php\?id=\d+&keywords=&tid=0&lid=0$') # 问号转义 rules = (
Rule(link1, callback='parse_item', follow=True),
Rule(link2, callback='parse_detail', follow=True),
) def parse_item(self, response):
# 岗位名称和类别
print('item',response)
tr_list = response.xpath('//table[@class="tablelist"]/tr[@class="odd"] | //table[@class="tablelist"]/tr[@class="even"]')
for tr in tr_list:
job_name = tr.xpath('./td[1]/a/text()').extract_first()
job_class = tr.xpath('./td[2]/text()').extract_first()
# 实例化item类
item = CrawlproItem()
item['job_name'] = job_name
item['job_class'] = job_class yield item def parse_detail(self, response):
# 岗位职责
desc = response.xpath('//ul[@class="squareli"]/li/text()').extract()
desc = ''.join(desc)
item = TenproItem_detail()
item['desc'] = desc
yield item
items.py文件:
import scrapy class CrawlproItem(scrapy.Item):
job_name = scrapy.Field()
job_class = scrapy.Field() class TenproItem_detail(scrapy.Item):
desc = scrapy.Field()
管道文件pipelines.py:
class CrawlproPipeline(object):
fp = None def open_spider(self, spider):
# 文件只打开一次
self.fp = open('./tenxun.txt', 'w',encoding='utf-8') def process_item(self, item, spider):
desc = None
# 取出item中的值 if item.__class__.__name__ == 'CrawlproItem':
job_name = item["job_name"]
job_class = item["job_class"]
self.fp.write(f'{job_name}\n{job_class}\n\n')
else:
desc = item['desc']
self.fp.write(desc)
return item # 返回给下一个即将被执行的管道类 def close_spider(self, spider):
self.fp.close()
配置文件中注意开启管道
利用Crawlspider爬取腾讯招聘数据(全站,深度)的更多相关文章
- 简单的scrapy实战:爬取腾讯招聘北京地区的相关招聘信息
简单的scrapy实战:爬取腾讯招聘北京地区的相关招聘信息 简单的scrapy实战:爬取腾讯招聘北京地区的相关招聘信息 系统环境:Fedora22(昨天已安装scrapy环境) 爬取的开始URL:ht ...
- 利用python爬取58同城简历数据
利用python爬取58同城简历数据 利用python爬取58同城简历数据 最近接到一个工作,需要获取58同城上面的简历信息(http://gz.58.com/qzyewu/).最开始想到是用pyth ...
- 利用scrapy爬取腾讯的招聘信息
利用scrapy框架抓取腾讯的招聘信息,爬取地址为:https://hr.tencent.com/position.php 抓取字段包括:招聘岗位,人数,工作地点,发布时间,及具体的工作要求和工作任务 ...
- Python 爬取腾讯招聘职位详情 2019/12/4有效
我爬取的是Python相关职位,先po上代码,(PS:本人小白,这是跟着B站教学视频学习后,老师留的作业,因为腾讯招聘的网站变动比较大,老师的代码已经无法运行,所以po上),一些想法和过程在后面. f ...
- 『Scrapy』爬取腾讯招聘网站
分析爬取对象 初始网址, http://hr.tencent.com/position.php?@start=0&start=0#a (可选)由于含有多页数据,我们可以查看一下这些网址有什么相 ...
- python3 scrapy 爬取腾讯招聘
安装scrapy不再赘述, 在控制台中输入scrapy startproject tencent 创建爬虫项目名字为 tencent 接着cd tencent 用pycharm打开tencent项目 ...
- Python爬虫入门——使用requests爬取python岗位招聘数据
爬虫目的 使用requests库和BeautifulSoup4库来爬取拉勾网Python相关岗位数据 爬虫工具 使用Requests库发送http请求,然后用BeautifulSoup库解析HTML文 ...
- 利用Jsoup爬取新冠疫情数据并存至数据库
需要用到的jar包(用来爬取的jsoup,htmlunit-2.37.0-bin以及连接数据库中的mysql.jar) 链接:https://pan.baidu.com/s/1VlylWmlhjd8K ...
- scrapy 第一个案例(爬取腾讯招聘职位信息)
import scrapy import json class TzcSpider(scrapy.Spider): # spider的名字,唯一 name = 'tzc' # 起始地址 start_u ...
随机推荐
- 201671010140. 2016-2017-2 《Java程序设计》java学习第十六周
java学习第十六周-并发 本周,学习了Java中线程,并发的知识,在老师的带领下,进行了对知识的理解学习,以及对实验的运行讲解,对这一块内容掌握的还可以,在自主编程中,也能够完成.线, ...
- mysql-5.6.24-win32解决没有my.ini并且修改编码
3.配置环境变量:新建一个系统变量: MYSQL_HOME, 值:D:\MySql\mysql5611 //这一步不做也行 4.修改MySql启动配置文件: 将安装目录下文件:my-default. ...
- IDEA 提示找不到 javax 等 tomcat 的相关包
网上很多方法都告诉你,把 javax 的 libs 拷贝到项目下吧,简直简单粗暴.其实有更好的办法. 1.首先进入 Run 其中的 Run/Debug Configurations,在 Server ...
- Mac shell使用技巧总结(转)
1.文件操作 常用目录 /Systme/Library/Extensions // 驱动所在目录 /User/XXX/Desktop // 桌面目录 资源库 chflags nohidden ~/Li ...
- 695. Max Area of Island最大岛屿面积
[抄题]: 求最多的联通的1的数量 Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (repre ...
- SpringIOC的理解
http://www.cnblogs.com/ITtangtang/p/3978349.html---IOC http://blog.csdn.net/fighterandknight/article ...
- xStream完美转换XML、JSON(转)
xStream框架 xStream可以轻易的将Java对象和xml文档相互转换,而且可以修改某个特定的属性和节点名称,而且也支持json的转换: 前面有介绍过json-lib这个框架,在线博文:htt ...
- 1083 Moving Tables
题目链接:http://poj.org/problem?id=1083 题意: 走廊两边分别有200个房间,一边连续编号为1-399的奇数,另一边是2-400的偶数, 如果从房间 i 移动桌子到房间 ...
- Yii2 中国省市区三级联动
1.获取源码:https://github.com/chenkby/yii2-region 2.安装 添加到你的composer.json文件 "chenkby/yii2-region&qu ...
- YII2 全局设定 默认参数
$gridviewSettings = [ 'export' => false, 'responsive' => true, 'floatHeader' => true, 'floa ...