我在获取图片网址时遇到困难。如何在 itemloader 中获取 image_url?如果我生成一个值为 image_url 的字典(没有 ItemLoader),它就可以正常工作。def parse_property(self, response): l = ItemLoader(item=PropertiesItem(), response=response) url=response.meta.get('URL') l.add_value('url', response.url) l.add_xpath('title', '//div[@class="property- title"]/h1/text()',MapCompose(str.strip, str.title)) l.add_xpath('offering', '//span[@class="property-badge"]/text()',MapCompose(str.strip)) l.add_xpath('area', '//ul[@class="property-main-features"]/li[contains(text(), "Area")]/span/text()',MapCompose(str.strip)) l.add_xpath('rooms', '//ul[@class="property-main-features"]/li[contains(text(), "Rooms")]/span/text()',MapCompose(str.strip)) l.add_xpath('bed_room', '//ul[@class="property-main-features"]/li[contains(text(), "Bedroom")]/span/text()',MapCompose(str.strip)) l.add_xpath('bath_room', '//ul[@class="property-main-features"]/li[contains(text(), "Bathroom")]/span/text()',MapCompose(str.strip)) #l.add_value('description', '//div[@class="description-div"]/ul/li/text()') #l.add_value('description', '//div[@class="description-div"]/p/text()') #l.add_value('description', '//div[@class="description-div"]/descendant::*/text()') l.add_xpath('ground_floor', '//*/strong[contains(text(), "Ground Floor")]/following-sibling::text()',MapCompose(str.strip)) l.add_xpath('first_floor', '//*/strong[contains(text(), "1st Floor")]/following-sibling::text()',MapCompose(str.strip)) l.add_xpath('top_floor', '//*/strong[contains(text(), "Top Floor")]/following-sibling::text()',MapCompose(str.strip)) l.add_xpath('facing', '//div[@class="additional-details"]/p[contains(text(), "Facing")]/text()',MapCompose(str.strip)) l.add_xpath('location', '//div[@class="additional-details"]/p[contains(text(), "Location")]/text()',MapCompose(str.strip)
1 回答
www说
TA贡献1775条经验 获得超8个赞
images=[i.split('?')[0] for i in image]
image_url=[x for x in images if 'original' in x]
l.add_value('images', image_url)
这将正常工作
添加回答
举报
0/150
提交
取消