Peter Pik
Peter Pik

Reputation: 11193

Scraping images using simple HTML DOM

I'm playing around with scraping image URLs, however, I can't seem to make it work.

So far, I've just found a test website which contain a teaser image, but it outputs nothing?

I've included the simple_html_dom.php file and then tried below code:

$afton_deep_link = file_get_html("http://esport.aftonbladet.se/csgo/csgo-tops-cash-betting-in-esports/");
$afton_img = $afton_deep_link->find("//div[@class='teaser-image-wrapper']//a/img", 0)->src;

echo $afton_img . "<br>";

Upvotes: 1

Views: 753

Answers (1)

Kevin
Kevin

Reputation: 41885

The image tag you're trying to get is inside a span:

$afton_deep_link = file_get_html("http://esport.aftonbladet.se/csgo/csgo-tops-cash-betting-in-esports/");
$afton_img = $afton_deep_link->find("//div[@class='teaser-image-wrapper']/div/span/img", 0)->{'data-default'};
echo $afton_img;

As an alternative, css selectors also work:

$afton_img = $afton_deep_link->find("div.teaser-image-wrapper div span img", 0)->{'data-default'};

Upvotes: 2

Related Questions