Reputation: 335
I have following HTML page:
<div class="showtime-bg">
<div style="float:left;">
<a href="javascript:getinfo(295, 1)"><img src="images/main/movies/movie.jpg" height="180" alt=""></a>
</div>
$dom = new DOMDocument();
@$dom->loadHTML($page);
$xpath_imgPath = new DOMXPath($dom);
$rightDivText_movie_path=$xpath_imgPath->query("//div[@class='showtime-bg']/div[0]/a/img[@src]");
How can I get the path using DOMDocument?
I am not able to retrieve the path.
Upvotes: 1
Views: 70
Reputation: 76656
The problem with your code is that you're using 0 as the base index. XPath starts the count from 1. You need to use div[1]
instead of div[0]
. Or just div
. Here's how you can get the image src:
$xPathQuery = "//div[@class='showtime-bg']/div/a/img";
$rightDivText_movie_path=$xpath_imgPath->query($xPathQuery);
echo $rightDivText_movie_path->item(0)->getAttribute('src');
Upvotes: 1