kxell2001
kxell2001

Reputation: 131

Get image src using scrapy python

I have following issue:

I want to scrape the src from a image using scrapy. Is it possible to do this in python (scrapy) like in javascript?

For instance:

<img class="test image_of_something" src="some_url">

The output should be "some_url". first problem: Somehow with

response.css("img")

i dont get all img-classes from the website. And is it possible to use some kind of queryselector? Since i want only specific image src. Like in javascript

document.querySelector(".image_of_something").src

i want to do this in pyhton. So far i stuck in my scrapy documentation.

Upvotes: 0

Views: 2122

Answers (1)

Ramy M. Mousa
Ramy M. Mousa

Reputation: 5933

First navigate to img element that contains your deisred class, then select the @src attribute.

Like this:

 image_url = response.xpath('//img[contains(@class,"image_of_something")]/@src').extract()[0]

Upvotes: 1

Related Questions