Reputation: 33
I'm currently attempting to scrape the site https://www.bloomingdales.com with scrapy.
In this project I'm attempting to extract the url of the main image loaded in each of the product pages e.g.:
However each picture is loaded with an image request on the website and so I can't simply xpath to locate the image url. How do I extract the image urls using scrapy?
Here's a screenshot of the requests I see in my chrome developer tools:
Upvotes: 3
Views: 1121
Reputation: 21436
It's quite common for e-commerce websites to store some json data in html body and then have the user's browser unpack it into a full page.
For this particular page if you copy the image url and search about in page source you can see all of the product data stored in:
<script id="pdp_data" type="application/json">some_json</script>
You can grab this data with scrapy and decode json to python dictionary:
data = response.xpath("//script[@id='pdp_data']/text()").extract_first()
import json
data = json.loads(data)
# then you can parse the data
data['product']['imageSource']
# '8/optimized/9216988_fpx.tif'
Upvotes: 4