2014-10-22 4 views
1

여기 http://simplehtmldom.sourceforge.net/manual.htm 발견하고 나는이 일을 제외하고 몇 가지 테스트 성공을 가지고 :PHP 간단한 HTML DOM 파서 - 중첩 된 요소를 분석 내가 PHP 간단한 HTML DOM 파서 설명서와 함께 놀았 던

그것은 중첩있어 테이블 및 스팬 및 I 스팬의 바깥 쪽 텍스트를 mynum 클래스로 파싱하고 싶습니다.

<?php 

require_once 'simple_html_dom.php'; 

$url = 'http://relumastudio.com/test/target.html'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21"); 
curl_setopt($ch, CURLOPT_URL, $url); 
$result = curl_exec($ch); 

$DEBUG = 1; 

if($DEBUG){ 
    $html = new simple_html_dom(); 
    $html->load($url); 
    echo $html->find('span[class=mynum]',0)->outertext; // I should get 123456 
}else{ 
    echo $result; 
}   
curl_close($ch); 

는 난 그냥 한번 텍스트 123456를 얻을 수 echo $html->find('span[class=mynum]',0)->outertext;에 전화로 도망 수 있다고 생각하지만 난 할 수 없습니다.

아이디어가 있으십니까? 어떤 도움이라도 대단히 감사합니다. 고맙습니다.

+0

컬 코드가 아닌 질문으로 html을 게시해야합니다. – pguardiario

답변

1

로드를 반환 outertext

$html = new simple_html_dom(); 
$html->load_file($url); 
echo $html->find('span[class=mynum]',0)->innertext; 

. 이 경우 ->innertext을 사용하십시오.

$url = 'http://relumastudio.com/test/target.html'; 
$html = file_get_html($url); 
$num = $html->find('span.mynum', 0)->innertext; 
echo $num; 
+0

효과가 있습니다! 고마워요 @ 고스트 – anagnam

+0

@reymangana 확실한 사람이 기꺼이 도와 줬습니다 – Ghost

+0

괜찮 으면 괜찮습니까? – anagnam

0

innertext가 필요합니다. 제대로 먼저 URL <span class="mynum">123456</span>

+0

@MIvanlsten, 나는 그것을 시도했지만 여전히 NULL을 반환합니다. – anagnam

+0

그 범위에 123456이 있습니까? 어쩌면 스팸이 비어 있으므로 결과가 반환되지 않습니다. –

+0

@AresDraguna 예. 이 URL을 조사해주십시오. http://relumastudio.com/test/target.html – anagnam

관련 문제