python类Spider()的实例源码

dmoz_spider.py 文件源码 项目:Spider 作者: shineyr 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def parse(self, response):

        """
        The lines below is a spider contract. For more info see:
        http://doc.scrapy.org/en/latest/topics/contracts.html
        @url http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/
        @scrapes name
        """
        sel = Selector(response)
        sites = sel.xpath('//ul[@class="directory-url"]/li')
        items = []
        for site in sites:
            item = DmozItem()
            item['title'] = site.xpath('a/text()').extract()
            item['link'] = site.xpath('a/@href').extract()
            item['desc'] = site.xpath('text()').re('-\s[^\n]*\\r')
            items.append(item)          
        return items


问题


面经


文章

微信
公众号

扫码关注公众号