2013-03-25 47 views
-2

这里的问题是:scrapy项目:何时退货?

  1. 我能找到的项目数据的网页,然后按照A的出站链接到 获得额外的项目数据。
  2. 附加项目数据位于B和C网页中。对于B有一个parse_b() ,对于C有一个parse_c()(这两个解析是在 parse_A())中的回调。此项目数据完成后。

那么,其中parse()返回物品?

+1

您在过去的回调返回的项目:parse_a返回请求(回调parse_b)... parse_b返回请求(回调parse_c).. 。parse_c返回Item。 – 2013-03-25 15:16:31

+0

它的工作原理,但有没有更好的方法? – st316 2013-03-26 07:20:15

回答

0

目光投向https://github.com/darkrho/scrapy-inline-requests

这似乎是这样的:

class FooSpider(BaseSpider): 
    @inline_request 
    def parse_a(self, response): 
     l = FooLoader() 
     l.add_value("A", "A") 
     b = yield Request(response.url + '/b) 
     l.add_value("B", b) 
     c = yield Request(response.url + '/c) 
     l.add_value("C", c) 
     yield l.load_item() 

    @inline_request 
    def parse_b(self, response): 
     # Doing what you want 
     return "B" 

    @inline_request 
    def parse_c(self, response): 
     # Doing what you want 
     return "C" 
+0

谢谢你的帮助!我会试试这个。 – st316 2013-03-29 08:48:24