Reputation: 131
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
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