我想從一個網站的數據存儲在一個內部div的所有圖像,我如何獲取所有圖像。我試過了,但它不能工作。這裏是我的代碼從網頁上刮取網頁數據
<?php
$html = file_get_contents('http://en.vonvon.me/'); //get the html returned from the following url
$pokemon_doc = new DOMDocument();
libxml_use_internal_errors(TRUE); //disable libxml errors
if(!empty($html)){ //if any html is actually returned
$pokemon_doc->loadHTML($html);
libxml_clear_errors(); //remove errors for yucky html
$pokemon_xpath = new DOMXPath($pokemon_doc);
//get all the h2's with an id
$pokemon_row = $pokemon_xpath->query('div[class=desc ng-binding]');
if($pokemon_row->length > 0){
foreach($pokemon_row as $row){
echo $row->nodeValue . "<br/>";
}
}
}
?>
那麼,有什麼問題?沒有或錯誤的輸出?錯誤訊息?檢查錯誤日誌? Btw ..如果你的代碼不起作用,你應該刪除'@'符號,因爲這些符號會抑制錯誤消息,這在調試時很有用。 –