1

My question is very direct. Here is my html dom,

<html>
   ...
  <div class="A B">
    <div class="C">
       <img src="..." >
    </div>
  <div>
  ...
  <div class="A">
  </div>
...
</html>

Now I want to get the image's src in div[class="A B"]-><div class="C">-><img> using DOMXPath in php code.

The main puzzle is that I do not know how to write it's path correctly.


Update

I have tried How to get data from HTML using regex, but it doesn't work still.

The actual html structure is : enter image description here

My php code:

   $doc = new DOMDocument();
   $doc->loadHTML($html);
   $title = $doc->getElementsByTagName('title')->item(0)->nodeValue;
   $XPath = new DOMXPath($doc);
   $vipImg = $XPath->query('//div[@class="show-midpic active-pannel"]/a/div[@class="zoomPad"]/img');
   var_dump($vipImg);
   foreach($vipImg as $vip)
   {
      var_dump($vip);
   }

And the output is :

object(DOMNodeList)#2 (1) { ["length"]=> int(0) }

Community
  • 1
  • 1
chenzhongpu
  • 6,193
  • 8
  • 41
  • 79
  • This question is a duplicate of the following: http://stackoverflow.com/questions/10130858/get-img-src-with-php – Geoherna Aug 25 '15 at 02:59
  • @GeorgeH The main puzzle is that I do not know how to write it's path correctly. – chenzhongpu Aug 25 '15 at 03:03
  • Here's an answer I did last week that is pretty similar, http://stackoverflow.com/questions/32118367/how-to-get-data-from-html-using-regex/32118963#32118963. – chris85 Aug 25 '15 at 03:15

0 Answers0