我正在尝试使用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
的模块
答案 0 :(得分:1)
您需要Detect when browser receives file download:
from yourproject.items import TrousersItem