Scrapy:没有模块命名项目,刮图像

时间:2016-01-15 04:04:25

标签: python web-scraping scrapy

我正在尝试使用scrapy从网页下载图像的示例。

这是蜘蛛文件:

        .state('colleague', {
            url: "/colleague",

            templateUrl: "views/colleague.html",

            controller:  'colCtrl', // Notice its same level as resolve

            resolve: {
                typeEmployee: function ($q, $timeout) {
                    var deferred = $q.defer();
                    $timeout(function () {
                        deferred.resolve('manager');
                    }, 200);
                    return deferred.promise;
                }

            }
        })

还有items.py:

from scrapy import Spider, Item, Field, Request
from items import TrousersItem
class TrouserScraper(Spider):
    name, start_urls = "Trousers_spider", ["http://lookatmyfuckingredtrousers.blogspot.co.uk"]
    def parse(self, response):
        for image in response.selector.xpath('//*[contains(@class, "entry-content")]/div[contains(@class, "separator")]/a/img/@src'):
             yield TrousersItem(image_urls=[image.extract()])
        for url in response.selector.xpath("//*[contains(@class, 'blog-pager-older-link')]/@href"):
            yield Request(url.extract(), callback=self.parse)

当我输入

import scrapy
from scrapy.item import Item


class TrousersItem(scrapy.Item):
    image_urls = scrapy.Field()
    images = scrapy.Field()

我收到此错误:

  

没有名为items

的模块

1 个答案:

答案 0 :(得分:1)

您需要Detect when browser receives file download

from yourproject.items import TrousersItem

假设import items from your project package