这里是我用于爬取网页的代码。我想抓取的网站图片延迟加载启用,所以scrapy只能抓取100张图片中的10张,其余都是placeholder.jpg。在Scrapy中处理延迟加载图像的最佳方式是什么?如何使用python Scrapy惰性加载图像
谢谢!
class MasseffectSpider(scrapy.Spider):
name = "massEffect"
allowed_domains = ["amazon.com"]
start_urls = [
'file://127.0.0.1/home/ec2-user/scrapy/amazon/amazon.html',
]
def parse(self, response):
for item in items:
listing = Item()
listing['image'] = item.css('div.product img::attr(src)').extract()
listing['url'] = item.css('div.item-name a::attr(href)').extract()
listings.append(listing)
看来像CasperJS这样的其他工具有加载图像的视口。
casper.start('http://m.facebook.com', function() {
// The pretty HUGE viewport allows for roughly 1200 images.
// If you need more you can either resize the viewport or scroll down the viewport to load more DOM (probably the best approach).
this.viewport(2048,4096);
this.fill('form#login_form', {
'email': login_username,
'pass': login_password
}, true);
});
你能分享你正在爬行的网站吗?在一个pastebin将工作。 – eLRuLL