zoukankan      html  css  js  c++  java
  • scrapy基础知识之 CrawlSpiders(爬取腾讯校内招聘):

    import scrapy
    from scrapy.spider import CrawlSpider,Rule
    from scrapy.linkextractors import LinkExtractor
    from tencent.items import TencentItem

    class TencentSpider(CrawlSpider):
        name = "Tencent"
        allowed_domains = ["tencent.com"]
        # url="http://hr.tencent.com/position.php?&start="
        # offset=0
        start_urls = [ "http://hr.tencent.com/position.php?&start=0#a"]

        page_link=LinkExtractor(allow=("start=d+"))

        rules=[
                Rule(page_link,callback = "parseContent",follow=True)
        ]

        def parseContent(self, response):
            list=response.xpath('//tr[@class="even"] | //tr[@class="odd"]')
            for infos in list:
                item=TencentItem()
                item['positionname']=infos.xpath("./td[1]/a/text()").extract()[0]
                item['positionlink']=infos.xpath("./td[1]/a/@href").extract()[0]
                item['positionType']=infos.xpath("./td[2]/text()").extract()
                item['positionNum']=infos.xpath("./td[3]/text()").extract()[0]
                item['positionLocation']=infos.xpath("./td[4]/text()").extract()[0]
                item['publishTime']=infos.xpath("./td[5]/text()").extract()[0]

                yield item


    运行: scrapy crawl Tencent
    #注意:千万记住callback不能写 parse,由于CrawlSpider使用parse方法来实现其逻辑,如果覆盖了 parse方法,crawl spider将会运行失败
  • 相关阅读:
    关于字节对齐以及内存占用
    关于HandlerThread的分析
    关于栈和队列的相关操作
    自定义控件(View的绘制流程源码解析)
    关于采用github.io搭建个人博客
    算法题解
    关于Android中ArrayMap/SparseArray比HashMap性能好的深入研究
    ADB server didn't ACK * failed to start daemon *
    Handler 、 Looper 、Message
    KMP字符串模式匹配详解(转)
  • 原文地址:https://www.cnblogs.com/huwei934/p/6971251.html
Copyright © 2011-2022 走看看