Tencent 招聘信息网站

创建项目

scrapy startproject Tencent

创建爬虫

scrapy  genspider -t crawl tencent

1. 起始url  start_url = 'https://hr.tencent.com/position.php'

在起始页面,需要获取该也页面上的每个职位的详情页的url,同时需要提取下一页的url地址,做同样的操作。

因此起始页url地址的提取,分为两类:

  1. 每个职位详情页的url地址的提取

  2. 下一页url地址的提取,并且得到的页面做的操作和起始页的操作一样。

url地址的提取

1. 提取详情页url,详情页的url地址如下:

 提取规则详情页的规则:

rules = (
# 提取详情页的url地址 ,详情页url地址对应的响应,需要进行数据提取,所有需要有回调函数,用来解析数据 Rule(LinkExtractor(restrict_xpaths=("//table[@class='tablelist']//td[@class='l square']")), callback='parse_item')
)

提取下一页的htmlj所在的位置:

2 获取下一页的url 规则:

rules = (
# 提取详情页的url地址
# Rule(LinkExtractor(allow=r'position_detail.php?id=\d+\&keywords=&tid=0&lid=0'), callback='parse_item'), # 这个表达式有错,这里不用正则
Rule(LinkExtractor(restrict_xpaths=("//table[@class='tablelist']//td[@class='l square']")), callback='parse_item'),
# 翻页
Rule(LinkExtractor(restrict_xpaths=("//a[@id='next']")), follow=
True),
)

获取详情页数据

1.详情数据提取(爬虫逻辑)

1.获取标题

xpath:

item['title'] = response.xpath('//td[@id="sharetitle"]/text()').extract_first()

2. 获取工作地点,职位,招聘人数

xpath:

 item['addr'] = response.xpath('//tr[@class="c bottomline"]/td[1]//text()').extract()[1]

 item['position'] = response.xpath('//tr[@class="c bottomline"]/td[2]//text()').extract()[1]

 item['num'] = response.xpath('//tr[@class="c bottomline"]/td[3]//text()').extract()[1]

3.工作要求抓取

xpath:

item['skill'] =response.xpath('//ul[@class="squareli"]/li/text()').extract()

爬虫的代码:

# -*- coding: utf-8 -*-
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule from ..items import TencentItem class TencentSpider(CrawlSpider):
name = 'tencent'
allowed_domains = ['hr.tencent.com']
start_urls = ['https://hr.tencent.com/position.php'] rules = (
# 提取详情页的url地址
# Rule(LinkExtractor(allow=r'position_detail.php?id=\d+\&keywords=&tid=0&lid=0'), callback='parse_item'), # 这个表达式有错
Rule(LinkExtractor(restrict_xpaths=("//table[@class='tablelist']//td[@class='l square']")), callback='parse_item'),
# 翻页
Rule(LinkExtractor(restrict_xpaths=("//a[@id='next']")), follow=True),
) def parse_item(self, response): item = TencentItem() item['title'] = response.xpath('//td[@id="sharetitle"]/text()').extract_first() item['addr'] = response.xpath('//tr[@class="c bottomline"]/td[1]//text()').extract()[0] item['position'] = response.xpath('//tr[@class="c bottomline"]/td[2]//text()').extract()[0] item['num'] = response.xpath('//tr[@class="c bottomline"]/td[3]//text()').extract()[0] item['skill'] =response.xpath('//ul[@class="squareli"]/li/text()').extract() print(dict(item)) return item

tencent.py

2. 数据存储

1.settings.py 配置文件,配置如下信息

ROBOTSTXT_OBEY = False
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
ITEM_PIPELINES = {
'jd.pipelines.TencentPipeline': 300, }

2. items.py 中:

import scrapy

class TencentItem(scrapy.Item):
# define the fields for your item here like:
title = scrapy.Field()
addr = scrapy.Field()
position = scrapy.Field()
num = scrapy.Field()
skill = scrapy.Field()

3. pipeline.py中:

import  pymongo

class TencentPipeline(object):

    def open_spider(self,spider):
# 爬虫开启是连接数据库
client = pymongo.MongoClient() collention = client.tencent.ten self.client =client self.collention = collention pass
def process_item(self, item, spider): # 数据保存在mongodb 中 self.collention.insert(dict(item)) return item def colse_spdier(self,spider): # 爬虫结束,关闭数据库 self.client.close()

启动项目

1.先将MongoDB数据库跑起来。

2.执行爬虫命令:

scrapy  crawl  tencent

3. 执行程序后的效果:

使用scrapy-crawlSpider 爬取tencent 招聘的更多相关文章

  1. Scrapy框架——CrawlSpider爬取某招聘信息网站

    CrawlSpider Scrapy框架中分两类爬虫,Spider类和CrawlSpider类. 它是Spider的派生类,Spider类的设计原则是只爬取start_url列表中的网页, 而Craw ...

  2. Python爬虫【实战篇】scrapy 框架爬取某招聘网存入mongodb

    创建项目 scrapy startproject zhaoping 创建爬虫 cd zhaoping scrapy genspider hr zhaopingwang.com 目录结构 items.p ...

  3. Python+Scrapy+Crawlspider 爬取数据且存入MySQL数据库

    1.Scrapy使用流程 1-1.使用Terminal终端创建工程,输入指令:scrapy startproject ProName 1-2.进入工程目录:cd ProName 1-3.创建爬虫文件( ...

  4. 简单的scrapy实战:爬取腾讯招聘北京地区的相关招聘信息

    简单的scrapy实战:爬取腾讯招聘北京地区的相关招聘信息 简单的scrapy实战:爬取腾讯招聘北京地区的相关招聘信息 系统环境:Fedora22(昨天已安装scrapy环境) 爬取的开始URL:ht ...

  5. 爬虫07 /scrapy图片爬取、中间件、selenium在scrapy中的应用、CrawlSpider、分布式、增量式

    爬虫07 /scrapy图片爬取.中间件.selenium在scrapy中的应用.CrawlSpider.分布式.增量式 目录 爬虫07 /scrapy图片爬取.中间件.selenium在scrapy ...

  6. scrapy-redis + Bloom Filter分布式爬取tencent社招信息

    scrapy-redis + Bloom Filter分布式爬取tencent社招信息 什么是scrapy-redis 什么是 Bloom Filter 为什么需要使用scrapy-redis + B ...

  7. scrapy-redis分布式爬取tencent社招信息

    scrapy-redis分布式爬取tencent社招信息 什么是scrapy-redis 目标任务 安装爬虫 创建爬虫 编写 items.py 编写 spiders/tencent.py 编写 pip ...

  8. python-scrapy爬取某招聘网站(二)

    首先要准备python3+scrapy+pycharm 一.首先让我们了解一下网站 拉勾网https://www.lagou.com/ 和Boss直聘类似的网址设计方式,与智联招聘不同,它采用普通的页 ...

  9. 使用scrapy框架爬取自己的博文(2)

    之前写了一篇用scrapy框架爬取自己博文的博客,后来发现对于中文的处理一直有问题- - 显示的时候 [u'python\u4e0b\u722c\u67d0\u4e2a\u7f51\u9875\u76 ...

随机推荐

  1. tp框架中的一些疑点知识-6

    vim自带一个目录浏览器,使用命令:E就可以调出来,实际上就是浏览器的名字就是"网络读写"netrw vim也自带了 补全功能, 启动键是 "ctrl_N" 或 ...

  2. luogu1975 [国家集训队]排队

    思路 序列中 |i | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| |----|--|--|--|--|--|--|--|--|--|--| |a[i]| a| b| c| L| d ...

  3. hihoCoder week23 最短路径·一

    spfa 最短路 #include <bits/stdc++.h> using namespace std; #define pb push_back #define INF 1e16; ...

  4. IDEA入门及maven配置

    idea基本使用 下载安装 idea下载地址 激活方法 上面的失效使用这个 配置SDKs和编译版本 选择jdk 我是主要用于Java开发,因此配置JDK8 配置编码 其他配置 个人配置主题等 注意 与 ...

  5. C#数字前面如何补0

    PadLeft()函数:向左补齐PadRight()函数:向右补齐 class Program { static void Main(string[] args) { ; Console.WriteL ...

  6. Vue学习二:v-model指令使用方法

    本文为博主原创,未经允许不得转载: <!DOCTYPE html> <html lang="zh"> <head> <script src ...

  7. win7 "com surrogate“ 已停止工作的解决办法

    1.在文件夹选项里选“始终显示图标,从不显示缩略图”. 2.数据执行保护(DEB),依次打开:计算机——属性——高级系统设置——高级——性能——设置——数据执行保护 选下面的单选按钮“为除下列选定程序 ...

  8. 【译】第10节---数据注解-Key

    原文:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.asp ...

  9. _itemmod_rate_stone

    `entry`几率宝石物品ID `type` 1--合成对应_itemmod_exchange_item 2--强化对应_itemmod_exchange_item 3-附魔(除itemMask = ...

  10. mybatis 学习总结笔记Day2

    在门外听到或看到一门技术,找资料入门,一看,嗯,不错,进门之后,发现,尼玛————,是片海,你是关门而出,还是学习精卫填海. 填海吧,也许只是个小水坑,稍加用点力,就填的7788了. 上一篇随笔中说了 ...