scrapy crawlspider 腾讯招聘

scrapy的一个小分支,主要是利用正则,匹配url,

第一个rule实现自动翻页,

第二个rule实现提取内容,

愿大家每天进步一点点,会发现生活如此美好~

能看到这篇文章,相信,老铁已经在爬虫的路上,走过一段时间了,给部分想踏入爬虫这个行业的人,

推荐一本书:《Python爬虫开发与项目实战》

不用买,网上就有,里面都是基础,在面试中磨练基础,在项目中磨练经验

import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from tencent_job.items import TencentJobItem


class TxjobSpider(CrawlSpider):
    name = 'txjob'
    allowed_domains = ['tencent.com']
    start_urls = ['https://hr.tencent.com/position.php?&start=0#a']
    item = TencentJobItem()
    rules = (
        Rule(LinkExtractor(allow=r'&start=\d+'), follow=True),
        Rule(LinkExtractor(allow=r'\?id=\d+'), callback='parse_item'),
    )

    def parse_item(self, response):
        item = TencentJobItem()
        item['title'] = response.xpath('//td[@id="sharetitle"]/text()').extract_first()
        item['address'] = response.xpath('//tr[@class="c bottomline"]/td[1]/text()').extract_first()
        item['type'] = response.xpath('//tr[@class="c bottomline"]/td[2]/text()').extract_first()
        item['count'] = response.xpath('//tr[@class="c bottomline"]/td[3]/text()').extract_first()
        item['responsibility'] = response.xpath('//ul[@class="squareli"]//text()').extract()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值