Questo dovrebbe funzionare, ma è disordinato e possibile si romperà se il sito che si sta raschiando capita di cambiare è markup che interesserà la raschiatura:
$sites[0] = 'http://www.traileraddict.com/';
// use this if you want to retrieve more than one page:
// $sites[1] = 'http://www.traileraddict.com/trailers/2';
foreach ($sites as $site)
{
$ch = curl_init($site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
// ok, you have the whole page in the $html variable
// now you need to find the common div that contains all the review info
// and that appears to be <div class="info"> (I think you could use abstract aswell)
$title_start = '<div class="info">';
$parts = explode($title_start,$html);
// now you have an array of the info divs on the page
foreach($parts as $part){
// so now you just need to get your title and link from each part
$link = explode('<a href="/trailer/', $part);
// this means you now have part of the trailer url, you just need to cut off the end which you don't need:
$link = explode('">', $link[1]);
// this should give something of the form:
// overnight-2012/trailer
// so just make an absolute url out of it:
$url = 'http://www.traileraddict.com/trailer/'.$link[0];
// now for the title we need to follow a similar process:
$title = explode('<h2>', $part);
$title = explode('</h2>', $title[1]);
$title = strip_tags($title[0]);
// INSERT DB CODE HERE e.g.
$db_conn = mysql_connect('$host', '$user', '$password') or die('error');
mysql_select_db('$database', $db_conn) or die(mysql_error());
$sql = "INSERT INTO trailers(url, title) VALUES ('".$url."', '".$title."')"
mysql_query($sql) or die(mysql_error());
}
Dovrebbe essere così, ora hai una variabile per il link e il titolo che puoi inserire nel tuo database.
NEGAZIONE
Ho scritto questo dalla parte superiore della mia testa sul lavoro quindi mi scuso se non funziona immediatamente il blocco, ma fatemi sapere se non lo fa e io cercherò di aiutare ulteriormente.
ANCHE, sono consapevole che questo potrebbe essere fatto in modo più intelligente e utilizzando meno passaggi ma ciò implicherebbe un maggior pensiero da parte mia e l'OP può farlo se lo desiderano una volta che hanno capito il codice che ho scritto, poiché assumerei sarebbe molto più importante capire cosa ho fatto ed essere in grado di modificarlo da soli.
Inoltre, vorrei consigliare di raschiare il sito di notte in modo da non appesantirlo con il traffico extra e vorrei suggerire di chiedere il permesso di quel sito così da quando se ti prendono saranno in grado di mettere fine al tuo raschiando :(
per rispondere alla tua ultimo punto - per eseguire questo in un periodo di tempo impostato si usa un job cron
ho provato alcuni script php (riccio e file_get_contents) che ho trovato nel net.but. questi script recuperano solo l'intera pagina Web e non i dati specifici. Inoltre non so come salvare quei dati nel mio database mysql – Eka
Cerca su google phpquery o htmlsql o simplehtmldom – Sarfraz