51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2358|回复: 4
打印 上一主题 下一主题

[求助] Python自定义翻页老出现问题

[复制链接]
  • TA的每日心情
    无聊
    5 天前
  • 签到天数: 406 天

    连续签到: 3 天

    [LV.9]测试副司令

    跳转到指定楼层
    1#
    发表于 2019-1-7 09:27:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    1测试积点
    学习爬京东众筹前50页热卖商品信息,可以翻页,但不按顺序翻页,乱跳,请问是哪里出现问题了呢
    1. import scrapy
    2. # 导入items类, 使items类生效
    3. from jd1.items import Jd1Item
    4. import time

    5. class Jdzch1Spider(scrapy.Spider):
    6.     name = 'jdzch1'
    7.     start_urls = ['https://z.jd.com/bigger/search.html?sort=zhtj&page=1']

    8.     def parse(self, response):
    9.             result = response.xpath('//li[@class="info type_now"]')
    10.         # 循环每个商品,提取所需信息
    11.             for i in result:
    12.             # 定义 item 字典
    13.                 item = Jd1Item()
    14.                 # 筛选信息
    15.                 item['title'] = i.xpath('.//h4[@class="link-tit"]/text()').extract_first()
    16.                 item['perc'] = i.xpath('.//li[@class="fore1"]/p[@class="p-percent"]/text()').extract_first()
    17.                 item['outc1'] = i.xpath('.//li[@class="fore1"]/p[@class="p-extra"]/text()').extract_first()
    18.                 item['money'] = i.xpath('.//li[@class="fore2"]/p[@class="p-percent"]/text()').extract_first()
    19.                 item['outc2'] = i.xpath('.//li[@class="fore2"]/p[@class="p-extra"]/text()').extract_first()
    20.                 item['time'] = i.xpath('.//li[@class="fore3"]/p[@class="p-percent"]/text()').extract_first()
    21.                 item['outc3'] = i.xpath('.//li[@class="fore3"]/p[@class="p-extra"]/text()').extract_first()
    22.                 yield item
    23.             time.sleep(3)

    24.     def start_requests(self):
    25.         j = 1
    26.         for j in range(5,0)[::-1]:      
    27.             newurl = "https://z.jd.com/bigger/search.html?sort=zhtj&page=%d"  %  (j)
    28.             yield scrapy.Request(newurl, callback=self.parse)
    复制代码


    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    5 天前
  • 签到天数: 1670 天

    连续签到: 3 天

    [LV.Master]测试大本营

    2#
    发表于 2019-1-8 09:27:40 | 只看该作者
    def start_requests(self):
            for j in range(1,51):      
                newurl = "https://z.jd.com/bigger/search.html?sort=zhtj&page=%d"  %  (j)
                yield scrapy.Request(newurl, callback=self.parse)
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2021-12-27 08:30
  • 签到天数: 471 天

    连续签到: 1 天

    [LV.9]测试副司令

    3#
    发表于 2019-1-8 10:34:03 | 只看该作者
    因为抓取的时候是按照响应速度抓取的
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    5 天前
  • 签到天数: 1389 天

    连续签到: 3 天

    [LV.10]测试总司令

    4#
    发表于 2019-1-8 10:51:11 | 只看该作者
    翻页的话找下一页
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    5 天前
  • 签到天数: 2663 天

    连续签到: 3 天

    [LV.Master]测试大本营

    5#
    发表于 2019-1-8 11:16:11 | 只看该作者
    按照上面的试下
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-5-5 23:24 , Processed in 0.067810 second(s), 21 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表