2011-03-29 109 views
0

我试图将外部网页的某些信息导入到数组中。将表中的元素插入到数组中

这里是阅读页面的代码:

$url = 'http://dsrd.uc.cl/dara/libcursos/periodo21/ptj/ptj_5_data.html'; 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); 
curl_setopt ($ch, CURLOPT_HTTPHEADER, array (
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" 
)); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
// get the source code 
$html = curl_exec($ch); 

,这里是代码即可获得列到一个数组

$doc = new DOMDocument(); 
$doc->loadHTML($html); 
$table = $doc->getElementsByTagName("table")->item(0); 
$rows = $table->getElementsByTagName("td"); 

for ($i = 0; $i<100; $i++) 
{ 
    $curso[$i] = $rows->item($i); 

    /* Find columns and add it to your array */ 
} 
print_r($curso); 

但即时通讯只获得了充满“一个DOMElement对象数组()“

任何消耗? THX

UPDATE

忘了添加 - >的nodeValue; ....只是愚蠢

THX反正

回答

0

你把DOMElement的在里面,所以当然那是什么你得到。根据您的需要,您还可以存储$rows->item($i)->value$rows->item($i)->tagName$rows->item($i)->textContent$rows->item($i)->ownerDocument->saveXML($rows->item($i))

你有什么数据想要那里?