2013-10-04 2 views
0

I합니다 (IMG 링크를 얻을)이 사이트를 분석하려고 사용 :구문 분석 IMG RSS 피드에서 PHP 간단한 HTML DOM 파서

include 'parse/simple_html_dom.php'; 

// Create DOM from URL or file 
$html = file_get_html('http://statigr.am/feed/parishilton/'); 

// Find all images 
foreach($html->find('img') as $element) 
{ 
     echo $element->src . '<br>'; 
}  

스크립트 : http://statigr.am/feed/parishilton

이 내 코드입니다 아무것도 돌려주지 않는다! 왜 그런가요? img 링크가 필요합니다.

답변

0

모든 이미지 CDATA 섹션 안에있는 파서가이를 무시, 그래서 솔루션이 반환 된 내용에서 모든 CDATA를 교체하고 다음을 통해 해당 문자열 및 루프에서 DOM 개체를 만드는 데 str_get_html를 사용

$html = file_get_html('http://statigr.am/feed/parishilton/'); 
$html = str_replace("<![CDATA[","",$html); // clean-up 
$html = str_replace("]]>","",$html); // clean-up 
$html = str_get_html($html); // re-construct the dom object 
// Loop 
foreach($html->find('item description img') as $el) 
{ 
    echo $el->src . "<br />"; 
} 

이기 때문이다 이미지. (테스트를 거쳐 작동합니다).

출력 :

http://distilleryimage3.s3.amazonaws.com/cc25d8562c9611e3a8b922000a1f8ac2_8.jpg 
http://distilleryimage7.s3.amazonaws.com/4d8e22da2c8911e3a6a022000ae81e78_8.jpg 
http://distilleryimage5.s3.amazonaws.com/ce6aa38a2be711e391ae22000ae9112d_8.jpg 
http://distilleryimage3.s3.amazonaws.com/d64ab4c42bc811e39cbd22000a1fafdb_8.jpg 
...... 
...... 
+0

감사합니다! 동일한 배열에 링크, 설명 및 게시 시간을 표시하려면 어떻게해야합니까? 출력 : 1. 링크 : 즐 설명 : XX 시간 : XX 2. 링크 설명 : XX 시간 : XX –

+0

'foreach는 ($, HTML> $ 엘 등 ('항목')를 찾을 수 있습니다) \t { \t echo $ el-> find ('description img', 0) -> src. "
"; \t echo $ el-> find ('link', 0) -> innertext. "
"; \t echo $ el-> find ('pubDate', 0) -> innertext. "
"; \t} –

+0

[문서 읽기] (http://simplehtmldom.sourceforge.net/manual.htm#section_quickstart). –

관련 문제