我有一个提取营业时间的蜘蛛,它工作正常。我怎么也无法隐藏传递给另一个项目的项目值,这些项目在最终输出中不再显示。有人可以帮助我吗
class WrapItemList(scarpy.Item):
mon = scrapy.Field()
tue = scrapy.Field()
wed = scrapy.Field()
thu= scrapy.Field()
sat= scrapy.Field()
sun= scrapy.Field()
businessHours=scrapy.Field()
列表中的列表:
il = MySiteLoader(selector=details,item=WrapListItem())
il.add_xpath('mon','.........')
il.add_xpath('tue','.........')
il.add_xpath('wed','.........')
il.add_xpath('thu','.........')
il.add_xpath('fri','.........')
il.add_xpath('sat','.........')
il.add_xpath('sat','.........')
il.add_value('businessHours',"Mon":il.get_output_value('mon'),"Tue":il.get_output_value('tue'),"Wed":il.get_output_value('wed'),"Thu":il.get_output_value('thu'),"Fri":il.get_output_value('fri'),"Sat":il.get_output_value('sat'),"Sun":il.get_output_value('sun')})
mon: 10 AM - 6 PM tue: 10 AM - 6 PM wed: 10 AM - 6 PM thu: 10 AM - 6 PM fri: 10 AM - 6 PM sat: 10 AM - 6 PM sun: 10 AM - 6 PM
Business Hours :{mon: 10 AM - 6 PM tue: 10 AM - 6 PM, wed: 10 AM - 6 PM, thu: 10 AM - 6 PM, fri: 10 AM - 6 PM, sat: 10 AM - 6 PM. sun: 10 AM - 6 PM}
Business Hours :{mon: 10 AM - 6 PM tue: 10 AM - 6 PM, wed: 10 AM - 6 PM, thu: 10 AM - 6 PM, fri: 10 AM - 6 PM, sat: 10 AM - 6 PM. sun: 10 AM - 6 PM}
答案 0 :(得分:0)
感谢所有人。我能够在Github的帮助下解决。以下代码工作正常。
from scrapy.contrib.loader.processor import TakeFirst
[...]
il.add_value('businessHours', "Mon": il.get_xpath('.....', TakeFirst()), ...)