利用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 ...
随机推荐
- launcher启动应用重启的BUG解决
最近遇到了一个问题,从launcher重新进入已经运行的应用会直接跳到应用的第一个界面. 经过对应用的跟踪,结合网络上的资料 http://stackoverflow.com/questions/19 ...
- Oracle-属性查询
1. 查询表的部分字段属性 select t.*, c.comments from user_tab_columns t, user_col_comments c where t.table_name ...
- Java中的静态代理实现方式
1.编写一个接口类 如:Subject package com.neusoft.pattern.staticProxy; /** * <p>Title:</p> * <p ...
- jedis的publish/subscribe[转]含有redis源码解析
首先使用redis客户端来进行publish与subscribe的功能是否能够正常运行. 打开redis服务器 [root@localhost ~]# redis-server /opt/redis- ...
- Python使用日常
#Python中文件夹和文件的判断import os My_Path = "/home/lpworkstudy/Gooddir/" #现在我们判断这个文件夹是否存在 #如果不存在, ...
- tomcat端口作用
<Server port="8005" shutdown="SHUTDOWN"> <Connector port="8080&q ...
- python str, list,tuple, dir
Python3 字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello ...
- 将windows上面的项目拷贝到Linux环境下报错不能够找到对应的表com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'puyang.ServiceType' doesn't exist
将一模一样的项目从win迁移到到linux上报错: 一开始还是以为是linux不能识别hql语句,查找资料发现是因为Liunx服务器上mysql是区分大小写的,而本地是不区分的如:代码是这样写的 @E ...
- C#记录程序运行时间
主要:using System.Diagnostics;当中有Stopwatch类: 介绍如下: // 摘要: // 提供一组方法和属性,可用于准确地测量运行时间. public class Stop ...
- 洛谷P2147[SDOI2008]洞穴勘测(lct)
题目描述 辉辉热衷于洞穴勘测. 某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好两个洞穴.假 ...