python - Getting data from response meta or getting data from item loader. Which is better? -
i have written spider sending data parent function child function via meta. in child function parsing these items. if data not found in response.meta.get('name')
writing xpath in child function.
which better way in these two?
1)
item.add_value('name', response.meta.get('name')) if not item.get_output_value('name'): item.add_xpath('name', 'xpath')
2)
if response.meta.get('name', ''): item.add_value('name', response.meta.get('name')) else: item.add_xpath('name', 'xpath')
to avoid work setting , getting item value (snippet 1), first value meta
, check it:
value = response.meta.get("name") if not value: item.add_xpath("name", "xpath") else: item.add_value("name", value)
Comments
Post a Comment