2014-09-05 1 views
1

I가 특정 링크에서 링크를 얻을 다음 코드를간단한 PHP DOM 파서 - 찾을 요소

if($site === 'Test') { 
    $list = $html->find('div.most-viewed-section ol li'); 
    foreach($list as $item) { 
     $link = $item->find('a', 0)->href; 
     $headline = $item->find('a', 0)->innertext; 
     $image = $item->find('span.image-optional a img', 0); 
      if($image) { 
      $image = $image->src; 
      } 
    $Post[] = array('link' => $link, 'headline' => $headline, 'image' => $image); 
    } 
} 

하지만 지금은 또한 다음과 같은 링크 요소 찾기 수행 할 작업 :

$link = $item->find('a', 0)->href; 

아무에게도이를 달성하는 방법에 대한 제안이 있습니까? 감사

답변

0

거기에 태그 내에서 이미지가이고 당신이 이미지 SRC를 얻을 수 원한다면 당신은 .. 체인 수 있어야한다, 등 뭔가 아래 작동합니다 :

$image = $item->find('a', 0)->find('img', 0)->src;