|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
怎么不爬第二页啊是不是我yield缩进问题,求大佬看看
- # -*- coding: utf-8 -*-
- import scrapy
- from Tengxun.items import TengxunItem
- class TengxunSpider(scrapy.Spider):
- name = 'tengxun'
- allowed_domains = ['https://hr.tencent.com']
- baseURL = 'https://hr.tencent.com/position.php?&start='
- offset = 0
- start_urls = [baseURL + str(offset)]
- def parse(self, response):
- node_list = response.xpath('//tr[@class="even"] | //tr[@class="odd"]')
- for node in node_list:
- item = TengxunItem()
- item['positionName'] = node.xpath('.//a/text()').extract()[0]#职称
- item['positionLink'] = node.xpath('.//a/@href').extract()[0]#详情
- if len(node.xpath('./td[2]/text()')):
- item['positionType'] = node.xpath('./td[2]/text()').extract()[0]#类别
- else:
- item['positionType'] = ' '
- item['peopleNumber'] = node.xpath('./td[3]/text()').extract()[0]#人数
- item['workLocation'] = node.xpath('./td[4]/text()').extract()[0]#地点
- item['publishTime'] = node.xpath('./td[5]/text()').extract()[0]#.encode('utf-8')
- yield item #for循环取每一个值并返回,取完六个值再执行下面if
- if self.offset < 2950:
- self.offset += 10
- #offset值为整型,字符串相加要转换成str类型
- url = self.baseURL + str(self.offset)
- #callback = self.parse 指定函数
- yield scrapy.Request(url,callback = self.parse) #访问第二页并将参数带入进入for循环
复制代码
cmd 执行到翻页代码返回信息,也没报错就是不知道为什么没爬第二页
2018-10-28 21:01:45 [scrapy.spidermiddlewares.offsite] DEBUG: Filtered offsite request to 'hr.tencent.com': <GET https://hr.tencent.com/position.php&start=10>
2018-10-28 21:01:45 [scrapy.core.engine] INFO: Closing spider (finished)
2018-10-28 21:01:45 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
本帖最后由 wongyusing 于 2018-10-28 22:14 编辑
你这个代码是看网上的scrapy的教材对吧?
我没记错的话后面是一个for,没有if吧。
还有个可能性是每次不是加10吧。
你去看下页面每次加多少。
还有个可能性,由于某个岗位缺少某个参数导致报错,使爬虫中断
|
|