Issue
I'm trying to download images using scrapy but the problem is, I couldn't found path to get that image url. They are using s3 for their images. That's why if i type view(response) i can see blank gallery. So how can I get path or images link? Here is the website link. Please have a look site
Solution
- You can get the main image by using this xpath:
response.xpath('//meta[@property="og:image"]').extract_first()
- If you want all images: the links of the images are present in the html, but a bit hidden in a json-structure. The following code loads the json-structure into a python dictionary and gathers the image links:
import json
image_json = response.xpath('//*[@type="text/x-magento-init"][contains(text(), "mage/gallery/gallery")]/text()').extract_first().strip()
image_dict = json.loads(image_json)
images_data = image_dict['[data-gallery-role=gallery-placeholder]']['mage/gallery/gallery']['data']
image_urls = [image_data['img'] for image_data in images_data]
Answered By - Wim Hermans
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.