頑張れ!できる!できる!絶対できる!頑張れ!もっとやれるって!やれる!気持ちの問題だ!頑張れ!頑張れ!そこだ!そこだ諦めんな!絶対に頑張れ!積極的に!ポジティブに頑張る!頑張る!

  • Diary

Trekの評価プログラム修正しよっと;;

# ちなみにタイトルは誠さんエントリから


(追記 7/2 00:08)
とりあえずできた、ような気がする。
面倒くさがらずにさっさとやれば良かった....

ちなみにどぐされコードを一応続きにさらしておこうwww
動きゃいいんだ動きゃwwwww



freshreaderの表示htmlをローカル保存したものをinputに、TE/TL/TNの各ページのview数などを取得するphp(完全に自分用、この出力結果はまた別プログラムで利用するためのinputとなる)

<html>
<body>
 
<?php
 
mb_detect_order("UTF-8");
mb_http_output("UTF-8");
 
readandwrite("./うにゃ","./ほにゃ");
 
function readandwrite($url,$writefile) {
 
$inputdata = file($url);
$fp = fopen($writefile, 'w');
 
$num_data = 0;
$notfound_data =0;
$sleep_counter=0;
 
foreach ($inputdata as $line_input) {
 
    if (strpos($line_input,'<div class="itembody">') !== false ) {
        if ($trek_status == "page not found") {
            $trek_status = "";
            $notfound_data = $notfound_data + 1 ;
            // ヘッダのところで個別ページが404ならカウンタを進めずこの項目は終了
        } else {
 
            if ($trek_status != "got url") {
                echo "error: exist itembody before itemtitle.\n";
            }
            // サムネイルURL取得
            $line_input = strstr($line_input,'itembody">');
            $line_input = strstr($line_input,'img src=');
            $tmp_url = substr($line_input,9);
            $tmp_end = strpos($tmp_url,'">');
            $trekdata[$num_data]["thumbnailurl"] = substr($tmp_url,0,$tmp_end);
            
            $trek_status = "";
            
            print "url: ".$trekdata[$num_data]["url"]."\r\n";
            print "title: ".$trekdata[$num_data]["title"]."\r\n";
            print "thumbnail: ".$trekdata[$num_data]["thumbnailurl"]."\r\n";
            print "date: ".$trekdata[$num_data]["date"]."\r\n";
            print "viewed: ".$trekdata[$num_data]["viewed"]."\r\n";
            print "favorites: ".$trekdata[$num_data]["favorites"]."\r\n";
            print "points: ".$trekdata[$num_data]["points"]."\r\n";
            print "<br>\r\n";
            
            
            $num_data = $num_data +1;
                flush();
                ob_flush();
                    sleep(2);
        }
    }
 
    if (strpos($line_input,'<div class="itemtitle">') !== false ) {
        // trekページURL取得
        $line_input = strstr($line_input,'itemtitle">');
        $line_input = strstr($line_input,'a href=');
        $tmp_url = substr($line_input,8);
        $tmp_end = strpos($tmp_url,'">');
        $trekdata[$num_data]["url"] = substr($tmp_url,0,$tmp_end);
        
        // タイトル取得
        $tmp_url = strstr($tmp_url,'">');
        $tmp_url = substr($tmp_url,2);
        $tmp_end = strpos($tmp_url,'</a>');
        $trekdata[$num_data]["title"] = substr($tmp_url,0,$tmp_end);
        
        // trekの個別ページを見に行く
        $trek_page = file($trekdata[$num_data]["url"]);
        $exist_status = 0;
        $tmp_date = "";
        $tmp_viewed = "0";
        $tmp_favorites = "0";
        $tmp_points = "0";
        foreach ($trek_page as $line_trek) {
            //old date
            if (strpos($line_trek,'Date Submitted: <span') !== false ) {
                $line_trek = strstr($line_trek,'Date Submitted: <span');
                $line_trek = strstr($line_trek,'text">');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'<span');
                $tmp_date = substr($line_trek,0,$tmp_end); // まず年
                
                $line_trek = strstr($line_trek,'/span>');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'<span');
                $tmp_date = $tmp_date."-".substr($line_trek,0,$tmp_end); // 月
                
                $line_trek = strstr($line_trek,'/span>');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'<span');
                $tmp_date = $tmp_date."-".substr($line_trek,0,$tmp_end); // '日 時'
 
                $line_trek = strstr($line_trek,'/span>');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'</span');
                $tmp_date = $tmp_date.":".substr($line_trek,0,$tmp_end); // 分
                
                $exist_status = 1;
            }
            //new date and favorites
            if (strpos($line_trek,'Date Submitted: <em') !== false ) {
                $line_trek = strstr($line_trek,'Date Submitted: <em');
                $line_trek = strstr($line_trek,'<em>');
                $line_trek = substr($line_trek,4);
                $tmp_end = strpos($line_trek,'</em>');
                $tmp_date = substr($line_trek,0,$tmp_end); // 年-月-日 時:分
 
                $exist_status = 1;
 
                if (strpos($line_trek,'Favorites: <em') !== false ) {
                    $line_trek = strstr($line_trek,'Favorites: <em');
                    $line_trek = strstr($line_trek,'<em>');
                    $line_trek = substr($line_trek,4);
                    $tmp_end = strpos($line_trek,'</em>');
                    $tmp_favorites = substr($line_trek,0,$tmp_end);
                } else {
                    $tmp_favorites = 0;
                }
            }
 
            //old viewed
            if (strpos($line_trek,'Viewed: <span') !== false ) {
                $line_trek = strstr($line_trek,'Viewed: <span');
                $line_trek = strstr($line_trek,'text">');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'</span');
                $tmp_viewed = substr($line_trek,0,$tmp_end);
            }
 
            //new viewed
            if (strpos($line_trek,'Viewed: <strong') !== false ) {
                $line_trek = strstr($line_trek,'Viewed: <strong');
                $line_trek = strstr($line_trek,'trong>');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'</strong');
                $tmp_viewed = substr($line_trek,0,$tmp_end);
            }
 
            //old favorites
            if (strpos($line_trek,'Favorites: <span') !== false ) {
                $line_trek = strstr($line_trek,'Favorites: <span');
                $line_trek = strstr($line_trek,'text">');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'</span');
                $tmp_favorites = substr($line_trek,0,$tmp_end);
            }
 
            //old points
            if (strpos($line_trek,'Points: <span') !== false ) {
                $line_trek = strstr($line_trek,'Points: <span');
                $line_trek = strstr($line_trek,'text">');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'</span');
                $tmp_points = substr($line_trek,0,$tmp_end);
            }
 
            //new points
            if (strpos($line_trek,'Points: <strong') !== false ) {
                $line_trek = strstr($line_trek,'Points: <strong');
                $line_trek = strstr($line_trek,'trong>');
                $line_trek = substr($line_trek,6);
                $tmp_end = strpos($line_trek,'</strong');
                $tmp_points = substr($line_trek,0,$tmp_end);
            }
 
        
        // foreach ends
        }
        
        if ($exist_status == 0) {
            $trek_status = "page not found";
        } else {
            $trek_status = "got url";
            $trekdata[$num_data]["date"] = $tmp_date;
            $trekdata[$num_data]["viewed"] = $tmp_viewed;
            $trekdata[$num_data]["favorites"] = $tmp_favorites;
            $trekdata[$num_data]["points"] = $tmp_points;
        }
    // if of "itemtitle" ends
    }
 
// foreach ends
}
 
print "number of data:".$num_data."\r\n";
print "number of notfound-data:".$notfound_data."\r\n";
 
fclose($fp);
// function ends
}
 
?>
 
</body>
</html>

Track Back

Track Back URL

Comments [3]

nniがこわれた・・・。;;

と一瞬思ったw

其処を引っ張るとはwww

あのエントリ冒頭にめちゃくちゃ吹いたので:)

コメントする

公開されません

(いくつかのHTMLタグ(a, strong, ul, ol, liなど)が使えます)