账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    scrapy 的 -O命令保存的是空文件
    31
    0
    class EastSpider(scrapy.Spider):
        name = 'East'
        allowed_domains = ['****.com']
        start_urls = ['http://finance.***.com/news.html']
    
        def parse(self, response):
            nextUrl = response.xpath('//*[contains(@class,"page-btn")]/@href')
            for url in nextUrl.extract():
                time.sleep(1)
                yield Request(urljoin(response.url,url))
    
            contentUrl = response.xpath('//p[@class="title"]/a/@href')
            for urls in contentUrl.extract():
                time.sleep(1)
                yield Request(urls,callback = self.parse)
    
            pass

    代码如上,但是在命令行运行scrapy crawl East -o East.csv的结果,East.csv是个空文件,什么都没写进去。
    我看人家说要yield,但是自己搞了搞也没行...
    尝试了在for循环之外添加yield urlyield urls报错,说是在定义之前引用了,然后在for循环之内添加又没效果,还是空文件...

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • Joanna 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部