到指定目录下,创建个项目

进到 spiders 目录 创建执行文件,并命名

运行调试

执行代码,:

# -*- coding: utf-8 -*-
import scrapy
from ..items import TenXunItem class TenxunSpider(scrapy.Spider):
name = 'tenxun'
# allowed_domains = ['tenxun.com'] # 域名范围
start_urls = ['https://hr.tencent.com/position.php?lid=&tid=87&keywords']
burl = 'https://hr.tencent.com/' def parse(self, response):
tr_list = response.xpath('//table[@class="tablelist"]/tr')
for tr in tr_list[1:-1]:
item = TenXunItem()
item['position_name']=tr.xpath('./td[1]/a/text()').extract()[0]
item['position_link']=self.burl+tr.xpath('./td[1]/a/@href').extract()[0]
item['position_type']=tr.xpath('./td[2]/text()').extract()[0]
item['position_num']=tr.xpath('./td[3]/text()').extract()[0]
item['position_addr']=tr.xpath('./td[4]/text()').extract()[0]
item['position_time']=tr.xpath('./td[5]/text()').extract()[0] # yield item # 匹配下一页
next_url =self.burl + response.xpath('//div[@class="pagenav"]/a[11]/@href').extract()[0]
yield scrapy.Request(url=next_url, callback=self.parse) # 要获取内容,则要发起个新的请求, 回调函数 回调时传参
yield scrapy.Request(url = item['position_link'],callback=self.detail_tent,meta={'items': item}) def detail_tent(self,response):
# 得到上面传过来的参数
item = response.meta.get('items')
item['position_con'] = ''.join(response.xpath('//ul[@class="squareli"]//text()').extract()) yield item # # 名字
# position_name_list = response.xpath('//td[@class="l square"]/a/text()').extract()
# # 链接
# position_link_list = response.xpath('//td[@class="l square"]/a/@href').extract()
# # 类型
# position_type_list = response.xpath('//table[@class="tablelist"]/tr/td[2]/text()').extract()
# # 人数
# position_num_list = response.xpath('//table[@class="tablelist"]/tr/td[3]/text()').extract()
# print('====================')
# print('====================')
# print(self.burl + tr_list[2].xpath('./td[1]/a/@href').extract()[0])
# print('====================')
# print('====================')

  

pipelines.py
# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import json class TenXunPipeline(object):
def open_spider(self,spider):
self.f = open('tenxun.json', 'w', encoding='utf8') def process_item(self, item, spider):
conn = json.dumps(dict(item), ensure_ascii=False)+'\n'
self.f.write(conn)
return item def close_spider(self,spider):
self.f.close()

  

items.py
# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html import scrapy class TenXunItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
# 名字
print('00000000000000001111111111111111')
position_name = scrapy.Field()
# 链接
position_link = scrapy.Field()
# 类型
position_type = scrapy.Field()
# 人数
position_num = scrapy.Field()
# 地点
position_addr = scrapy.Field()
# 发布时间
position_time = scrapy.Field()
# 要求
position_con = scrapy.Field()

  

存入数据库:

潭州课堂25班:Ph201805201 爬虫高级 第三课 sclapy 框架 腾讯 招聘案例 (课堂笔记)的更多相关文章

  1. 潭州课堂25班:Ph201805201 爬虫高级 第七课 sclapy 框架 爬前程网 (课堂笔)

    定时对该网页数据采集,所以每次只爬第一个页面就可以, 创建工程 scrapy startproject qianchen 创建运行文件 cd qianchenscrapy genspider qian ...

  2. 潭州课堂25班:Ph201805201 爬虫高级 第六课 sclapy 框架 中间建 与selenium对接 (课堂笔记)

    因为每次请求得到的响应不一定是正常的,   也可以在中间建中与个类的方法,自动更换头自信,代理Ip, 在设置文件中添加头信息列表, 在中间建中导入刚刚的列表,和随机函数 class UserAgent ...

  3. 潭州课堂25班:Ph201805201 爬虫高级 第五课 sclapy 框架 日志和 settings 配置 模拟登录(课堂笔记)

    当要对一个页面进行多次请求时, 设   dont_filter = True   忽略去重 在 scrapy 框架中模拟登录 创建项目 创建运行文件 设请求头 # -*- coding: utf-8 ...

  4. 潭州课堂25班:Ph201805201 爬虫高级 第四课 sclapy 框架 crawispider类 (课堂笔记)

    以上内容以 spider 类 获取 start_urls 里面的网页 在这里平时只写一个,是个入口,之后 通过 xpath 生成 url,继续请求, crawispider 中 多了个  rules  ...

  5. 潭州课堂25班:Ph201805201 爬虫高级 第十三 课 代理池爬虫检测部分 (课堂笔记)

    1,通过爬虫获取代理 ip ,要从多个网站获取,每个网站的前几页2,获取到代理后,开进程,一个继续解析,一个检测代理是否有用 ,引入队列数据共享3,Queue 中存放的是所有的代理,我们要分离出可用的 ...

  6. 潭州课堂25班:Ph201805201 爬虫高级 第十一课 Scrapy-redis分布 项目实战 (课堂笔

  7. 潭州课堂25班:Ph201805201 爬虫高级 第十课 Scrapy-redis分布 (课堂笔记)

    利用 redis 数据库,做 request 队列,去重,多台数据共享, scrapy 调度 基于文件每户,默认只能在单机运行, scrapy-redis 默认把数据放到 redis 中,实现数据共享 ...

  8. 潭州课堂25班:Ph201805201 爬虫高级 第八课 AP抓包 SCRAPY 的图片处理 (课堂笔记)

    装好模拟器设置代理到 Fiddler  中, 代理 IP 是本机 IP, 端口是 8888, 抓包 APP斗鱼 用 format 设置翻页

  9. 潭州课堂25班:Ph201805201 爬虫基础 第三课 urllib (课堂笔记)

    Python网络请求urllib和urllib3详解   urllib是Python中请求url连接的官方标准库,在Python2中主要为urllib和urllib2,在Python3中整合成了url ...

随机推荐

  1. k64 datasheet学习笔记3---Chip Configuration之System modules

    1.前言 本文主要介绍芯片配置的系统模块的内容 2.SIM配置 TODO 3.SMC配置 TODO 4.PMC配置 TODO 5.LOW-LEAKAGE WAKEUP单元配置 TODO 6.MCM配置 ...

  2. zabbix通过简单shell命令监控elasticsearch集群状态

    简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...

  3. mysql报错问题解决MySQL server PID file could not be found!

    MySQL server PID file could not be found! 无法启动mysql服务 # service mysqld start MySQL server PID file c ...

  4. jdbc驱动加载

    使用sqlserver数据库时,加载驱动: Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Strin ...

  5. Android:视频(VideoView/MediaPlayer)

    Android之视频播放 VideoView if(android.os.Environment.getExternalStorageState().equals(android.os.Environ ...

  6. 电信运营商 IT 系统介绍

    业务支撑系统 BSS: Business support system  运营支撑系统 OSS: Operation support system  管理支撑系统 MSS: Management Su ...

  7. 12-关于DOM操作的相关案例

    1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE html> <h ...

  8. C <string.h>常用函数介绍

    1. strcpychar *strcpy(char *destin, char *source);功能:将source指向的字符串拷到destin. int main() { ]; "; ...

  9. LeetCode(64):最小路径和

    Medium! 题目描述: 给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小. 说明:每次只能向下或者向右移动一步. 示例: 输入: [   [1 ...

  10. php 爬取数据

    简单. 灵活.强大的PHP采集工具,让采集更简单一点. 简介: QueryList使用jQuery选择器来做采集,让你告别复杂的正则表达式:QueryList具有jQuery一样的DOM操作能力.Ht ...