2014-11-30 4 views
1

내가이 내가 싶어 같은구문 분석 HTML 문서는

<a href="www.myurl/point.html" class="l" style="color:#436DBA;" onclick="return rs(this,'8 Stunning Linguistic Miracles of The Holy Quran | Kinetic Typography 144p (Video Only).mp4');">&raquo; Download MP4 &laquo;</a> - <b>144p (Video Only)</b> - <span> 19.1</span> MB<br /> 

HTML 페이지는 간단한 DOM의 PHP 파서와 구문 분석이 말을하고 난 다운로드 MP4를 얻을 싶어 114p 19.1 나는이 코드를 시도하면서 같은 넣어

foreach($displaybody->find('a ') as $element) { 
     // echo $element->innertext . '<br/>'; 

그것은 오 제가 19.1 당신은 어떤 때문에 더 이상 <a> 태그를 사용할 수 없습니다

답변

0

을 저를 도와주세요 나머지 값은 MP4 114p를 다운로드 구문 분석 할 유일한 방법은 MP4 다운로드 반환 액세스하려는 텍스트가 더 이상에 있지 f를, 문서 자체를 대상으로 다음 ->plaintext 사용

// load the sites html page in DOMDocument 
$dom = new DOMDocument(); 
libxml_use_internal_errors(true); 
$html_page = file_get_contents('http://www.mohammediatechnologies.in/download/downloadtest.php?name=8KPEiGqDQHg'); 
$dom->loadHTML(mb_convert_encoding($html_page, 'HTML-ENTITIES', 'UTF-8')); 
libxml_clear_errors(); 
$xpath = new DOMXpath($dom); 

$data = array(); 
// target elements which is inside an anchor and a line break (treat them as each row) 
$links = $xpath->query('//*[following-sibling::a and preceding-sibling::br]'); 

$temp = ''; 
foreach($links as $link) { // for each rows of the link 

    $temp .= $link->textContent . ' '; // get all text contents 

    if($link->tagName == 'br') { 
     $unit = $xpath->evaluate('string(./preceding-sibling::text()[1])', $link); 
     $data[] = $temp . $unit; // push them inside an array 
     $temp = ''; 
    } 
} 

echo '<pre>'; 
print_r($data); 
: 여기
$html = <<<EOT 
<a href="www.myurl/point.html" class="l" style="color:#436DBA;" onclick="return rs(this,'8 Stunning Linguistic Miracles of The Holy Quran | Kinetic Typography 144p (Video Only).mp4');">&raquo; Download MP4 &laquo;</a> - <b>144p (Video Only)</b> - <span> 19.1</span> MB<br /> 
EOT; 

$displaybody = str_get_html($html); 
echo $displaybody->plaintext; 

이 XPath는 함께 DOMDocument 통해 각 행에 액세스하는 또 다른 방법입니다

Sample Output

+0

일반 텍스트 괜찮습니다하지만 난 해당 페이지의 코드 severl 움큼을 가지고뿐만 아니라 그것을 내가 모든 앵커 태그 내가 그것을 –

+0

처리 어떻게 한 줄에 표시됩니다 일반 텍스트를 변환하면 내가 여러 앵커 태그를 의미 @ 유 ser1735121하지만 나는 당신이 함께 일하는 것으로 추측 할 수 없다. 당신이 게시 한 것과 만 일할 수있다. 당신은 적어도 당신이 근근이 살아가고있는 사이트를 가지고 작업 할 필요가 있습니다. – Ghost

+0

나는이 사이트에서 일하고 있습니다. http://www.mohammediatechnologies.in/download/downloadtest.php?name=8KPEiGqDQHg 나는 URL을 분리하고 싶습니다. mp4 480 픽셀과 19.1 메가 비트 문자열을 다운로드하십시오. –