inserting elements of a table into an array
Im trying to get some info of an external webpage into arrays.
here is the code to read the page:
$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);
and here is the code to get the columns into an array
$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 colu开发者_开发百科mns and add it to your array */
}
print_r($curso);
however im only getting the arrays filled with "DOMElement Object ( )"
any sugestions? thx
UPDATE
forgot to add ->nodeValue;.... just stupid
thx anyways
You are putting DOMElement
's in it, so of course that is what you get. Depending on what you want, you could also store the $rows->item($i)->value
, $rows->item($i)->tagName
,$rows->item($i)->textContent
, or $rows->item($i)->ownerDocument->saveXML($rows->item($i))
.
What data do you want there?
精彩评论