コード例 #1
0
ファイル: Review.php プロジェクト: RyoBamboo/RoughSetSystem
 public static function getAmazonReview($item_code, $item_id)
 {
     // レビュー取得時はmax_execution_timeの制限を外す
     ini_set("max_execution_time", 0);
     $reviews = array();
     $page = 1;
     while (true) {
         $url = 'http://www.amazon.co.jp/product-reviews/' . $item_code . '/ref=cm_cr_dp_see_all_summary?ie=UTF8&sortBy=byRankDescending&showViewpoints=0&pageNumber=' . $page;
         $page++;
         $curl = curl_init($url);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         $html = curl_exec($curl);
         if ($html === false) {
             break;
         }
         //            preg_match_all('/<div class="reviewText">(.+)<\/div>/im', $html, $m);
         preg_match_all('/<span class="a-size-base review-text">(.+)<\\/span><\\/div><div class="a-row a-spacing-top-small/', $html, $m);
         if ($m[1] == false) {
             preg_match_all('/<div class="reviewText">(.+)<\\/div>/im', $html, $m);
         }
         if ($m[1] == false) {
             break;
         }
         // preg_match_all('/<span class="a-icon-alt">([0-5])<\/span>/', $html, $stars);
         preg_match_all('/<i class="a-icon a-icon-star a-star-([0-5]) review-rating">/', $html, $stars);
         $i = 0;
         foreach ($m[1] as $review) {
             //                $review = mb_convert_encoding($review, 'UTF-8', 'SJIS');
             $review = trim(strip_tags($review));
             // 改行削除
             $review = preg_replace('/(?:\\n|\\r|\\r\\n| | )/', '', $review);
             if ($stars[1][$i] >= 4) {
                 $is_bought = 1;
             } else {
                 $is_bought = 0;
             }
             Review::insert(array('item_id' => $item_id, 'content' => $review, 'is_bought' => $is_bought, 'created_at' => time(), 'updated_at' => time()));
             $i++;
         }
     }
     //        // 取得するレビュー数
     //        $count = 1252;
     //        $now = 0; // 現在の取得数
     //        //for ($i = 1; $i < $count/15 + 1; $i++) {
     //        for ($i = 1; $now < $count + 1; $i++) {
     //            $url = "http://review.rakuten.co.jp/item/1/{$item_code}/{$i}.1/";
     //
     //            $html = Html::getHtml($url);
     //
     //            preg_match_all('|<a .* href="(.*)">このレビューのURL|U', $html, $match, PREG_PATTERN_ORDER);
     //            if (!$match[1] && $now != 0) {
     //                return "レビューを取得することができませんでした。商品コードが正しくない可能性があります。";
     //            }
     //
     //            foreach($match[1] as $url) {
     //
     //                $html = Html::getHtml($url);
     //                $review = Html::splitHtml($html, '<dd class="revRvwUserEntryCmt description">', "</dd>");
     //
     //
     //                $now ++;
     //
     //                if($now > $count) {
     //                    break;
     //                }
     //            }
     //        }
 }
コード例 #2
0
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "review.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/jfindley2.ini");
$review = new Review(null, 1, 2, "It was ok", 1, null);
$review->insert($pdo);
$review->setReviewText("It was decent");
$review->update($pdo);
$review->delete($pdo);