これはかなり簡単です。
まず、このサイトからのリンクをすべて取得し、配列にそれらすべてを投げる:
set_time_limit(0);//this could take a while...
ignore_user_abort(true);//in case browser times out
$html_output=file_get_contents("http://zenhabits.net/archives/");
# -- Do a preg_match on the html, and grab all links:
if(preg_match_all('/<a href=\"http:\/\/zenhabits.net\/(.*)\">/',$html_output,$matches)) {
# -- Append Data To Array
foreach($matches[1] as $secLink) {
$links[] = "http://zenhabits.net/".$secLink;
}
}
私はあなたのためにこれをテストし、そして:すべて完了です
//first 3 are returning something weird, but you don't need them - so I shall remove them xD
unset($links[0]);
unset($links[1]);
unset($links[2]);
いいえ、時間をすべてのリンク(配列$リンク内)を通過し、その内容を取得する:
foreach($links as $contLink){
$html_output_c=file_get_contents("$contLink");
if(preg_match('|<div class=\"post\">(.*)</div>|s',$html_output_c,$c_matches)) {
# -- Append Data To Array
echo"data found <br>";
$contentFromPage[] = $c_matches[1];
}
else{echo "no content found in: $contLink -- <br><br><br>";}
}//end of foreach
私は基本的にはwritte (ここでは、テキストファイルにそれを置くものとする)ループコンテンツ配列を、
そして今..あなたのために全体のクローラスクリプトナ、とあなたがそれをやりたい:
あなたはまた、使用することができます
//$contentFromPage now contains all of div class="post" content (in an array) - so do what you want with it
foreach($contentFromPage as $content){
# -- We need a name for each text file --
$textName=rand()."_content_".rand().".txt";//we'll just use some numbers and text
//define file path (where you want the txt file to be saved)
$path="../";//we'll just put it in a folder above the script
$full_path=$path.$textName;
// now save the file..
file_put_contents($full_path,$content);
//and that's it
}//end of foreach
あなたのために書きますか?私はどこで法案を送っていますか? http://mattgemmell.com/2008/12/08/what-have-you-tried/ –