Exemplo n.º 1
0
function insert_database($products, $model, $name, $shundian_price, $con)
{
    // 查看tb_product表中已有的商品数据nid
    $sql = "SELECT nid FROM `tb_product`";
    $retval = mysql_query($sql, $con);
    if (!$retval) {
        die("Could not connect: " . mysql_error() . "   on line " . __LINE__ . "<br>\n\r");
    }
    $product_ids = [];
    while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
        $product_ids[] = $row['nid'];
    }
    //    print_r($product_ids);
    $data_string = '';
    foreach ($products as $item) {
        if (!in_array($item->nid, $product_ids)) {
            $item->shopLink = 'https:' . $item->shopLink;
            $item->detail_url = 'https:' . $item->detail_url;
            $rate = get_rateinfo($item->shopLink, $item->detail_url);
            //            print_r($rate);
            //            echo "\n\r";die();
            //            $des = $rate[1][0];
            //            $des_com_aver = $rate[2][0];
            //
            //
            //            $attitude = $rate[3][0];
            //            $attitude_com_aver = $rate[4][0];
            //
            //            $quatity = $rate[5][0];
            //            $quatity_com_aver = $rate[6][0];
            $des = $rate[1][0];
            $des_com_aver = $item->shopcard->description[2] / 100.0;
            $des_com_aver .= '%';
            if ($item->shopcard->description[1]) {
                $des_com_aver = '高于 ' . $des_com_aver;
            } else {
                $des_com_aver = '低于 ' . $des_com_aver;
            }
            $attitude = $rate[2][0];
            $attitude_com_aver = $item->shopcard->service[2] / 100.0;
            $attitude_com_aver .= '%';
            if ($item->shopcard->service[1] > 0) {
                $attitude_com_aver = '高于 ' . $attitude_com_aver;
            } else {
                $attitude_com_aver = '低于 ' . $attitude_com_aver;
            }
            $quatity = $rate[3][0];
            $quatity_com_aver = $item->shopcard->delivery[2] / 100.0;
            $quatity_com_aver .= '%';
            if ($item->shopcard->delivery[1]) {
                $quatity_com_aver = '高于 ' . $quatity_com_aver;
            } else {
                $quatity_com_aver = '低于 ' . $quatity_com_aver;
            }
            $credit = $item->shopcard->sellerCredit;
            $view_sales = intval($item->view_sales);
            if (!empty($item->comment_count)) {
                $comment_count = $item->comment_count;
            } else {
                $comment_count = 0;
            }
            // 拼接product数据
            $data_string .= "(NULL, '{$item->nid}', '{$item->category}', '{$model}', '{$name}', '{$shundian_price}', '{$item->nick}', '{$item->view_price}', '{$view_sales}', '{$comment_count}', '0', '{$credit}', '{$des}', '{$des_com_aver}', '{$attitude}', '{$attitude_com_aver}', '{$quatity}', '{$quatity_com_aver}', '1', '{$item->shopLink}'),";
        }
    }
    //    echo '<br><br>' . $data_string;//die();       //4294967295
    // 如果有数据则插入到数据库中tb_product表
    if ($data_string) {
        // 去掉最后位置的,
        $data_string = substr($data_string, 0, -1);
        $sql = "INSERT INTO `tb_product` (`id`, `nid`, `category`, `model`, `name`, `shundian_price`, `merchant_name`, `merchant_price`, `view_sales`, `reviews_count`, `is_coalition`, `credit`, `des`, `des_com_aver`, `attitude`, `attitude_com_aver`, `quatity`, `quatity_com_aver`, `good`, `shop_link`) VALUES {$data_string}";
        //        echo "<br>\n\r" . $sql."<br>\n\r";
        $retval = mysql_query($sql, $con);
        if (!$retval) {
            // 插入出错的数据status设置为0
            $sql = "UPDATE `tb_product_list` SET `status` = '0' WHERE `model` = '{$model}'and `name` = '{$name}'";
            $retval = mysql_query($sql, $con);
            if (!$retval) {
                print_r('Could not connect: ' . mysql_error() . "   on line " . __LINE__ . "<br>\n\r");
            }
            die('Could not enter data: ' . mysql_error() . "   on line " . __LINE__ . "<br>\n\r");
        }
        echo "Enter data successfully.<br>";
    }
}
Exemplo n.º 2
0
<?php

/**
 * Created by PhpStorm.
 * User: TopSage
 * Date: 2015/12/11
 * Time: 11:25
 */
$url = "https://store.taobao.com/shop/view_shop.htm?user_number_id=1134618424";
$ref = "https://detail.tmall.com/item.htm?id=43160516597&ad_id=&am_id=&cm_id=140105335569ed55e27b&pm_id=&_u=b88mh8r71af&abbucket=5";
$rate = get_rateinfo($url, $ref);
print_r($rate);
echo $rate[2][0];
/**
 * 返回描述相符、服务态度、物流服务分数
 */
function get_rateinfo($shopLink, $referer)
{
    $ch = curl_init();
    // 设置浏览器的特定header
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Connection: keep-alive", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Upgrade-Insecure-Requests: 1", "DNT:1", "Accept-Language: zh-CN,zh;q=0.8,en-GB;q=0.6,en;q=0.4,en-US;q=0.2", "Cookie:cna=ecujDgxJEU8CAdrwlTLMuyK+; thw=cn; miid=7140089985405878683; _m_user_unitinfo_=center; uc2=wuf=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DyuLwEC5VzXl67TX71pM-Pt5ijrzvVp76FosboF3-bRXW_TIMHJDVmk32CWs6e7ra1SuZudckIhHttgRUS5bN_0MaK1Kv-zHpfr0mjFVBPh-Crtxj19HCnfLT8x4uC3p5%26wd%3D%26eqid%3Db1f8688b001197fa000000035668de3b; uc3=nk2=AmkbKafOx9I%3D&id2=UU8PbnneKzSx&vt3=F8dAScPiH8lvv%2FHL%2BUQ%3D&lg2=UIHiLt3xD8xYTw%3D%3D; lgc=axianzia; tracknick=axianzia; mt=np=&ci=3_1; _cc_=U%2BGCWk%2F7og%3D%3D; tg=0; v=0; uc1=cookie14=UoWzUGNqTOEvsA%3D%3D; cookie2=1ced5c4d4b6a7b1add0410eb06484e62; t=441f8ce4777a72bb7ea38953b39d0d4c; swfstore=120797; linezing_session=hMm9a7tS3qYHsL73Sj1tw2F3_1449797234940pw2h_2; _tb_token_=e335ee7876383; _m_h5_tk=aba0e734db020aa34adfd0514ecfd3c6_1449808809939; _m_h5_tk_enc=6c30d6dfe9563ec6b0df80acad26be4f; x=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0%26__ll%3D-1%26_ato%3D0; l=AhgYtVan25wZHmxPB3HCKeCpaEiqAXyL; isg=E58CA9133C4A05BE6936C3EA5438AFC6"));
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36');
    // 在HTTP请求头中"Referer: "的内容。
    curl_setopt($ch, CURLOPT_REFERER, "https:{$referer}");
    curl_setopt($ch, CURLOPT_ENCODING, "gzip, deflate, sdch");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, $shopLink);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //302redirect
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);