$urlToScrap = "https://play.google.com/store/apps/details?id=flipboard.app#?t=W251bGwsMSwxLDIxMiwiZmxpcGJvYXJkLmFwcCJd";
$pageContentData = file_get_contents($urlToScrap);
$doc = new DOMDocument();
$doc->loadHTML($pageContentData);
$listOfDivs = $doc->getElementsByTagName("div");
foreach ($listOfDivs as $div) {
if($div->getAttribute("class") == "doc-banner-icon"){
$img = $div->getElementsByTagName("img");
var_dump($img->getAttribute("src"));
}
}
returns empty.
I have the following elements in the dom:
<div class="doc-banner-icon"><img src="somesrc"></div>
I'm trying to get the img src and since in the page there are many images, I would like to first get the parent div and then extract the image inside it.
The solution is here:
$urlToScrap = "https://play.google.com/store/apps/details?id=flipboard.app#?t=W251bGwsMSwxLDIxMiwiZmxpcGJvYXJkLmFwcCJd";
$pageContentData = file_get_contents($urlToScrap);
$doc = new DOMDocument();
$doc->loadHTML($pageContentData);
$listOfDivs = $doc->getElementsByTagName("div");
foreach ($listOfDivs as $div) {
if($div->getAttribute("class") == "doc-banner-icon"){
$listOfImages = $div->getElementsByTagName("img");
foreach($listOfImages as $img){
var_dump($img->getAttribute("src"));
}
}
}