dimanche 19 avril 2015

Get value of second , and second using Simple HTML DOM

I'm trying get values from a shoutcast songhistory (link).


The markup of page have 2 tables like:



<table>
<tbody>
<tr>
<td>Header Link 1</td>
<td>Header Link 2</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr> <td>Lengh of song 1</td> </tr>
<tr> <td>Song Title 1</td> </tr>
<tr> <td>Lengh of song 2</td> </tr>
<tr> <td>Song Title 2</td> </tr>
</tr>
</tbody>
</table>


I only need get the song title and save this on a database.


This is my code:



<?php
include_once('simple_html_dom.php');

ini_set('display_errors', true);
error_reporting(E_ALL);

$host="localhost";
$username="root";
$password="";
$database="titulos";

mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "No se puede conectar a la base de datos");

$html = file_get_html('http://ift.tt/1HGysGc');
$guardardato = "";

// Buscar
foreach($html->find('table', 2)->find('tr', 2) as $datossc) {
foreach($datossc->find('td') as $titulo) {

echo $titulo->plaintext .'<br>';
$guardardato .= $titulo->plaintext;
}
}

$guardardato = mysql_real_escape_string($guardardato);
$query = "INSERT INTO data(name) VALUES('$guardardato')";

mysql_query($query) or die(mysql_error());

$html->clear();
unset($html);
?>


The sql process is ok, but the simple dom does work..


I get that error:



Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\proyectos\radioargenta\oyentes\indexprueba.php on line 19



enter image description here


Can help me?


Thanks!


Aucun commentaire:

Enregistrer un commentaire