爬取tencent职位招聘的

本文介绍了一个使用Scrapy框架实现的爬虫程序,该程序能够从腾讯人力资源网站抓取招聘信息,包括职位名称、链接、类型、需求等详细信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from TencentSpider.items import TencentspiderItem,TencentDetailItem

class TencentSpider(CrawlSpider):
    name = 'tencent'
    allowed_domains = ['hr.tencent.com'] # 如果指定,如果其他网站匹配到了下面的格式的话,就会去
    # 别的网站去爬取
    start_urls = ['https://hr.tencent.com/position.php?&start=0']
    """
        LinkExtractor(allow='start=\d+')返回的是一个列表,Rule依次发送请求,并且继续跟进,调用指定函数去处理
    """
    rules = [
        # Rule(LinkExtractor(allow='start=\d+'), callback='parse_tencent', follow=True),
        Rule(LinkExtractor(allow='position_detail.php'),callback='parse_info',follow=True)
    ]


    def parse_tencent(self, response):
        link_list = response.xpath("//tr[@class='even'] | //tr[@class='odd']")  #可以这样筛选
        for each in link_list:
            item = TencentspiderItem()
            item['position_name'] = each.xpath("./td[1]/a/text()").extract()[0]
            item['position_link'] = each.xpath("./td[1]/a/@href").extract()[0]
            position_type = each.xpath("./td[2]/text()").extract()[0]
            if not position_type:
                position_type = "为空"
            item['position_type'] = position_type
            item['position_need'] = each.xpath("./td[3]/text()").extract()[0]
            item['position_place'] = each.xpath("./td[4]/text()").extract()[0]
            item['position_time'] = each.xpath("./td[5]/text()").extract()[0]
            yield item


    """这个可以将 本页面中的链接都取出来进去将数据爬下来"""
    def parse_info(self,response):
        """可以将"""
        item = TencentDetailItem()
        item['position_name'] = response.xpath('//*[@id="sharetitle"]').extract()[0]

        yield item


"""其他设置和其他文章没有太大的区别"""

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值