Home > other >  Scrapy Item Field serializer
Scrapy Item Field serializer

Time:10-08

There is a example:
 import scrapy 

Def do_sth (text) :
If the text=="lianxiang" :
Return "lenovo"


The class Product (scrapy. Item) :
Name=scrapy. Field (serializer=do_sth)
Price=scrapy. Field ()

My_product=Product ()
My_product/" name "=" lianxiang "
My_product [" price "]=5000

Print (my_product)

Scrapy framework, the definition of Item, there is a serializer, optional parameters (line 9)
My understanding is that this parameter is a function name,
To pass into the value of the Item, use this function again, first in the value to the Item,
Don't know understand it right?
But in the process of execution (the example above), feel this function does not play a role,
The result is:
 {' name ':' lianxiang ', 'price: 5000} 

Excuse me, I understand it, or the process where there is a problem?

  • Related