scrapy框架学习-爬取腾讯社招信息-tencent.py

来源:互联网 发布:制造图片的软件 编辑:程序博客网 时间:2024/05/13 23:58

功能:设置起始URL和爬取范围,设置要提取的数据路径,返回item或下一个URL地址

# -*- coding: utf-8 -*-import scrapyfrom Tenxun.items import TenxunItemclass TencentSpider(scrapy.Spider):    name = 'tencent'    allowed_domains = ['tencent.com']    start_urls = ['http://hr.tencent.com/position.php?&start=0']    def parse(self, response):        nodelist = response.xpath("//tr[@class='even'] | //tr[@class='odd']")        for node in nodelist:            item = TenxunItem()            item['job_name'] = node.xpath("./td[1]/a/text()").extract()[0]            item['job_link'] = node.xpath("./td[1]/a/@href").extract()[0]            if len(node.xpath("./td[2]/text()")):                item['job_type'] = node.xpath("./td[2]/text()").extract()[0]            else:                item['job_type'] = "NULL"            item['job_people_num'] = node.xpath("./td[3]/text()").extract()[0]            item['job_site'] = node.xpath("./td[4]/text()").extract()[0]            item['publish_time'] = node.xpath("./td[5]/text()").extract()[0]            yield item        if len(response.xpath("//a[@class='noactive' and @id='next']")) == 0:            url = response.xpath("//a[@id='next']/@href").extract()[0]            yield scrapy.Request("http://hr.tencent.com/" + url, callback=self.parse)
阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 断丝锥如何取出 水龙头断丝取出器 断丝 丝锥断了怎么拿出来 断丝取出器价格 断丝锥取出器使用方法 偶断丝莲陈瑞歌曲 耦断丝连陈瑞原唱 快熔断保险丝 跌落式熔断器熔丝计算 快断保险丝 快速熔断保险丝 弃房断供 断供 抽刀断水水更流 断刀 断刀纪录片全集 抽刀断水 断刀全集观看 天师神医 抽刀断水 断刀客 演员 断刀纪录片全集10 抽刀断水水更流下一句 抽刀断水 天师神医 真三国无双6天断刀 通天主宰 残火断刀 都市神农医仙 抽刀断水 田园夫子之春满园 断刀眉 断刃 断刃txt下载 断刃 柳残阳 断刺 断刺演员表 谍战剧断刺 唐栋 断刺 断刺好看吗 断刺剧情介绍 断刺完整免费看 断剑重铸之日骑士归来之时 断剑 断剑神曲