I really like the official explanation in the docs:
Commodity loaders provide a convenient mechanism for filling scrapers. Even if items can be populated using a proprietary dictionary-like API, product loaders provide a much more convenient API for populating them from the scraping process, by automating some common tasks, such as parsing raw data before assigning it.
In other words, the elements provide a container of scraped data, while the Loaders element provides a mechanism for filling this container.
The last paragraph should answer your question.
Merchandise loaders are great as they allow you to have so many shortcuts to process and reuse a bunch of code so everything is neat, clean and clear.
An example of a comparison example. Let's say we want to clear this item:
class MyItem(Item): full_name = Field() bio = Field() age = Field() weight = Field() height = Field()
The only view approach would look something like this:
def parse(self, response): full_name = response.xpath("//div[contains(@class,'name')]/text()").extract()
vs Item Loaders:
As you can see, the item loader is much cleaner and easier to scale. Let's say you have 20 more fields, of which the same processing logic shares a lot, it would be suicide to do this without Item Loaders. Commodity trucks are awesome and you must use them!
Granitosaurus
source share