-1

I'm trying to extract srcset attribute of a img tag using pyquery & python3.

<img alt="my-image" srcset="//url/i/need/to/extract">

Extracting alt attribute works like expected, and returns "my-image"

(".item-thumb img").attr('alt')

But this method doesn't work for the attribute srcset. It returns None

(".item-thumb img").attr('srcset') #doesn't work
(".item-thumb img").attr.srcset #doesn't work

How to solve this? If there is no built-in way, may be a regular expression? Thanks.

nipunasudha
  • 2,427
  • 2
  • 21
  • 46

1 Answers1

0

Turns out, although the attribute is just srcset, you need to use data-srcset instead. This line works like a charm.

(".item-thumb img").attr('data-srcset')

I don't know what is the reason for this behavior though.

nipunasudha
  • 2,427
  • 2
  • 21
  • 46