これは、詳しい説明は、しません。
内容自分で解析するかして理解して下さい。
わからない方は、そういうもんだと考えてお使い下さい。
この中の処理は、実際にコミックページのhtml を解析し、必要な情報を取得するのに必要なキーワードを見つけ、必要情報を取得してデータを作成する処理です。
それを説明するのは、サイトに失礼ですし、やるべきでは無いと考えます。
サイトの各ページの癖を解析し、記載ルールを調査して作成しました。
以下にソースをのせます。
",$l);
$story=substr($html,$l+13,$nl-($l+13));
$story=trim($story);
$story = str_replace(array("\r\n", "\r", "\n"), '', $story);
$story = str_replace("
", '
', $story);
$l=strpos($story, "※ 配信方法によって収録内容が異なる場合があります。");
if($l){
$story=substr($story,0,$l);
}
}
return $story;
}
if(isset($_REQUEST['title']) ){
$ss=$_REQUEST['title'].",".$_REQUEST['pic'].",".$_REQUEST['jurl'].",".$_REQUEST['story'].",".$_REQUEST['saito_uri'].",".$_REQUEST['sdate']."\n";
print $ss."
";
$ss2=$_REQUEST['title'].",".$_REQUEST['pic'].",".$_REQUEST['jurl'].",".$_REQUEST['story'].",".$_REQUEST['saito_uri'].",".$_REQUEST['sdate'].",".date("Y/m/d H:i:s")."\n";
$OutoFile = $_REQUEST['OutFile'];
if (!is_file($OutoFile)){
$file = fopen($OutoFile, "w");
}
else {
$file = fopen($OutoFile, "a");
}
fwrite($file,$ss);
fclose($file);
print "終了
";
print "
";
print "
";
}else if(isset($_REQUEST['saito_uri']) ){
$OutoFile = $_REQUEST['OutFile'];
if (!is_file($OutoFile)){
$file = fopen($OutoFile, "w");
fclose($file);
}
$html = getFileMain($_REQUEST['saito_uri']);
$file = new SplFileObject("test.html", "w");
$file->fwrite($html);
//タイトル
$st = getTitle($html);
if($st!=""){
print "タイトル:".$st."
";
//電子書籍販売日
$sdate = getcDate($html);
if($sdate!=""){
print "電子書籍販売日:".$sdate."
";
//画像
$spic = getpic($html);
if( $spic!=""){
print "画像URL:".$spic."
";
print "
";
//立ち読み
$sturl = getTatiyomi($html);
if(true /*$sturl!=""*/){
print "立ち読みURL:".$sturl."
";
$story=getStory($html);
if( true){
print "説明:".$story."
";
$file = fopen($OutoFile, "r");
$cunt=0;
while (!feof($file)){
$str = fgets($file);
if($story!=""){
if((strpos($str,$story,0)>-1) &&(strpos($str,$st,0)>-1)){
$cunt++;
}
}
else{
if(strpos($str,$st,0)>-1){
$cunt++;
}
}
}
fclose($file);
if($cunt>0){
print "
";
print "
";
}
else{
print "
";
print "
";
}
}
else {
print "説明取得エラー
";
}
}
else {
print "立ち読み飛び先取得エラー
";
}
}
else {
print "画像取得エラー
";
}
}
else{
print "電子書籍販売日エラー
";
}
}
else {
print "タイトル取得エラー<7ys>";
}
//$domDocument = new DOMDocument();
//var_dump($html);
// print $html."
";
// $file = new SplFileObject("test2.html", "w");
// $file->fwrite($html);
}
else if( isset($_REQUEST['tgt'])){
if( $_REQUEST['type']=="コミック" ){
$OutoFile = "comic.csv";
}
else {
$OutoFile = "book.csv";
}
$fpath = $_REQUEST['tgt']."/".$OutoFile;
print "出力ファイル:".$fpath."
";
print "
";
}
else if( isset($_REQUEST['OutFile'])){
print "出力ファイル:".$_REQUEST['OutFile']."
";
print "
";
print "
";
}
else {
$result = list_files("./");
print "
";
}
?>
いかがでしょうか?
結構大きいプログラムとなってます。
取得される情報は、タイトルや画像URL 立ち読み先リンクURL コミックページURLコミック内容 などです。実際にサイトで使用する時は自分のDMM アフィリエイトID を加えて使用する必要があります。
getFileMain
この処理は、
file_get_contents関数を作り直した処理です。結果は同じになります。
file_get_contents関数は、制限があり、携帯php では使えますが、レンタルサーバーでは、制限に引っかかって使えない事が多いので、ネットで調べて作成しました。
この処理は、他のサーバーのファイル情報をテキストに全て読み込みます。
この処理によりDMM サイトのコミックページの内容を全て読み込み解析し、広告に必要な情報を抽出してファイルに保存します。
この処理は、実行すると、test.html ファイルを保存します。
これは、実際に読み込みしたDMM サイトの情報を保存した物です。
取得エラーが出た時の確認用です。デバッグに使用します。
次は、ftp のファイルアップを公開しますね!