scrapy框架学习-爬取腾讯社招信息-item字段和管道文件

本文介绍了如何利用Scrapy框架来爬取腾讯的社招信息,详细讲解了item定义和pipeline的运用,以实现数据的有效抓取和处理。
摘要由CSDN通过智能技术生成

item

# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html

import scrapy


class TenxunItem(scrapy.Item):
    # define the fields for your item here like:
    job_name = scrapy.Field()

    job_link = scrapy.Field()

    job_type = scrapy.Field()

    job_people_num = scrapy.Field()

    job_site = scrapy.Field()

    publish_time = scrapy.Field()

pipelines

# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html


import json


class TenxunPipeline(object):
    def __init__(self):
        self.f = open("tencent.json", "w")

    def process_item(self, item, spider):
        content = json.dumps(dict(item),
                             ensure_ascii=False) + ",\n"                                                             "\n"
        self.f.write(content)
        return item

    def close_spider(self, spider):
        self.f.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值