2013-08-25 60 views
1

在接收响应我要下载并显示验证码图片,然后继续爬行后,我的蜘蛛:如何在Scrapy中返回项目后继续爬网?

def get_captcha(self, response): 
     print '\nLoading captcha...\n' 
     item = CaptchaItem() 
     hxs = HtmlXPathSelector(response) 
     captcha_img_src = hxs.select('//*[@id="captcha-image"]/@src').extract()[0] 
     item['image_urls'] = [captcha_img_src] 
     return item 

但加载图像时,我不知道如何继续以后爬行。

提示:验证码图片无法无Cookie下载。

在此先感谢!

+0

你想要做什么?这段代码没有给你带来所有的验证码?请elaboratye? – Tushar

+0

我想显示下载的验证码,然后用scrapy发送邮寄请求 – olysachok

回答

0

使用收益,而不是回报:

def get_captcha(self, response): 
    print '\nLoading captcha...\n' 
    item = CaptchaItem() 
    hxs = HtmlXPathSelector(response) 
    captcha_img_src = hxs.select('//*[@id="captcha-image"]/@src').extract()[0] 
    item['image_urls'] = [captcha_img_src] 
    yield item 
    #you may display here your scraped item and after that 
    #your further post request goes here... 
    yield your_request