1

応答を受け取った後、スパイダーでキャプチャ画像をダウンロードして表示し、クロールを続けたい:

    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 なしではダウンロードできません。

前もって感謝します!

4

1 に答える 1

0

return の代わりに yield を使用します。

 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
于 2013-08-26T11:41:30.547 に答える