利用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 ...
随机推荐
- Canny效果
- spring4-2-bean配置-3-自动装配
- Linux arp命令
一.简介 arp命令用于操作主机的arp缓冲区,可以用来显示arp缓冲区中的所有条目.删除指定的条目或者添加静态的ip地址与MAC地址对应关系. 二.语法 -a<主机>:显示arp缓冲区的 ...
- Openssl crl命令
一.简介 crl命令用于处里PME或DER格式的CRL文件 二.语法 openssl crl [-inform PEM|DER] [-outform PEM|DER] [-text] [-in fil ...
- p4688 [Ynoi2016]掉进兔子洞
传送门 分析 我们考虑先将所有数离散化 之后我们对于每个状态用一个bitset来记录 其中第i段表示颜色i的信息 对于每一段信息均是段首若干1,剩余若干0表示这种颜色有多少个 于是我们不难想到莫队 答 ...
- Web测试实践--Rec 4
累计完成任务情况: 阶段内容 参与人 整理小组工作记录,维护小组博客 小尹 分析产品并撰写文档相关板块 小靳 撰写文档中对被测系统进行功能性分析相关板块 小龙.小黄 撰写文档中用户调研相关板块 小熊 ...
- mysql 数学操作函数
-- 绝对值,圆周率 SELECT ABS(-1),3*PI() -- 平方根,求余 SELECT SQRT(9),MOD(9,5) -- 获取整数的函数 SELECT CEIL(12.145),CE ...
- Word文档发布到CSDN博客
目前大部分的博客作者在写博客这件事情上都会遇到以下3个痛点:1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.2.发布到博客或公众号平台 ...
- 在Chrome 39中无法使用插件
在chrome 42+版本中在开启npapi选项. 1.打开插件面板,在地址栏中输入 chrome://plugins 2.找到npScreenCapture插件,点击始终允许选框 3允许控件
- SpringMVC源码解读 - HandlerMapping - SimpleUrlHandlerMapping初始化
摘要: SimpleUrlHandlerMapping只是参与Handler的注册,请求映射时由AbstractUrlHandlerMapping搞定. 初始化时,通过setMappings(Prop ...