Answer the question
In order to leave comments, you need to log in
How to get background-image:url in Mojo::DOM?
Hello! Not strong in Mojo::DOM and perl in general, the documentation gives examples of getting src from img, but I need to pull an image from background-image, can you tell me how?
...
imgSrc => $item->at('.image') ? $item->at('.image')->attr('src') : ''
...
Answer the question
In order to leave comments, you need to log in
Show an html example where you need to get a picture from background-image, because background-image is a css property, respectively, I assume it will be
If so, then here is an example code:
perl -MMojo::DOM -MDDP -E 'my $html = q|<div id="divimage" style="background-image:url/image.gif"></div>|; say $html; my $dom = Mojo::DOM->new($html); my $image = $dom->at("#divimage")->attr("style"); say $image; $image =~ s/^background-image:(.*?.gif)/$1/; say $image'
<div id="divimage" style="background-image:url/image.gif"></div>
background-image:url/image.gif
url/image.gif
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question