これは動作するはずですが、それは厄介だと可能性あなたがスクレーピングしているサイトは、それが掻き影響するマークアップです変更し発生した場合には解除されます:
$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());
}
を
これで、データベースに挿入できるリンクとタイトルの変数が追加されました。それはストレートバットオフ動作しますが、そうでないなら、私が知っていると私がしようとしますしない場合、私は謝罪ので、私は仕事で私の頭の上からこれを書いた
免責
さらに助けてください。
また、よりスマートに、より少ないステップを使用することができると私は認識していますが、私が書いたコードを理解すれば、彼らが私がやったことを理解して、自分でそれを編集できるようになることはずっと重要です。
また、余分なトラフィックに負担をかけることがないように、夜間にサイトを掻き集めることをお勧めします。また、そのサイトの許可を求めることもお勧めします。彼らがあなたをつかまえれば、あなたに終止符を打つことができるからです。あなたの最終点に答えるために:(
をこする - 。あなたはcronジョブを使用する設定時間でこれを実行するために
私はnet.butで見つかったいくつかのPHPスクリプト(カールとのfile_get_contents)を試してみましたそれらのスクリプトは、特定のデータではなく、全体のウェブページを取得するだけです。私はまた、自分のmysqlデータベースにそれらのデータを保存する方法を知らない – Eka
Googleのphpqueryまたはhtmlsqlまたはsimplehtmldomで検索 – Sarfraz