0

I am scraping for HD images in an e-commerce site. This is the html block containing the url I want, as seen in the dev tools.

<img class="_3togXc _3wp706" alt="" src="https://rukminim1.flixcart.com/image/880/1056/jtn9bww0/t-shirt/5/g/g/m-hm-1001-black-red-helmont-original-imafdfvvr8hqdu65.jpeg?q=50">

But trying to extract src through response.xpath('//img[@class="_3togXc _3wp706"]/@src').extract() is returning an empty list.

Here is the webpage: https://www.flipkart.com/mufti-striped-men-henley-neck-blue-t-shirt/p/itmf97tf5musdzhn?pid=TSHF97EQJFKYZNVR&lid=LSTTSHF97EQJFKYZNVRTO8NYI&marketplace=FLIPKART&srno=b_1_2&otracker=nmenu_sub_Men_0_T-Shirts&fm=organic&iid=en_gnuFJK6aCYh16bFjfooxjvp8RCgW1Qv5%2FUGcIk2pk%2B0jLtbLFo%2BqPL6Dtf5pUqburiU8mTUCC4lmPqYF651UZQ%3D%3D&ppt=browse&ppn=browse&ssid=mjlrz5luxs0000001570554928173

Please help! Thanks.

Nikhil
  • 1

2 Answers2

0

Check what's in the response. Looks like it is generated on the client-side.

Also you should not select by classes using XPath like this, at least use contains() for each class (or more complex https://stackoverflow.com/a/1604480/964478), or better use CSS selectors (img._3togXc._3wp706).

Alex P.
  • 3,697
  • 9
  • 45
  • 110
0

Try this

In [7]: response.xpath('//*[@class="_2_AcLJ _3_yGjX"]/@style').extract_first()
Out[7]: 'background-image:url(https://rukminim1.flixcart.com/image/128/128/jy1v7gw0/t-shirt/7/q/h/m-mfk-6564-g-16-blue-mufti-original-imaf97tfrbhdnhhn.jpeg?q=70)'

or

In [11]: response.xpath('//*[@class="_2_AcLJ _3_yGjX"]/@style').re_first('background-image:url\((.*)\)')
Out[11]: 'https://rukminim1.flixcart.com/image/128/128/jy1v7gw0/t-shirt/7/q/h/m-mfk-6564-g-16-blue-mufti-original-imaf97tfrbhdnhhn.jpeg?q=70'

final

response.xpath('//*[@class="_2_AcLJ _3_yGjX"]/@style').re('background-image:url\((.*)\)')

replace /image/128/128/ ------ /image/800/960

Wertartem
  • 237
  • 2
  • 5