Ejemplo n.º 1
0
function calMin($priceL, $priceR)
{
    global $search_res;
    $left = $priceL;
    $right = $priceR;
    while ($left < $right) {
        $mid = $left + $right >> 1;
        //echo "LL:".$priceL."L:".$left."R:".$right."mid:".$mid."\n";
        $search_url = $search_res . "[{$priceL},{$mid}]";
        $total = calTotal($search_url);
        if ($total == 3) {
            continue;
        }
        echo $left . ":" . $right . ":" . $mid . ":" . $total . "\n";
        if ($total > 10000) {
            $right = $mid;
            continue;
        } else {
            if ($total < 9000) {
                $left = $mid + 1;
                continue;
            }
        }
        break;
    }
    if ($priceL == $mid) {
        $mid++;
    }
    echo "                           total:" . $total . " " . "mid:" . $mid . "\n";
    if ($total > 100000) {
        exit;
    }
    return $mid;
}
Ejemplo n.º 2
0
$locnames = json_decode($locname, true);
$cats = array("50012027", "50012042", "50012028", "50029451", "50027236", "50043914", "50012047");
$search_res = "http://list.taobao.com/itemlist/.htm?json=on&pSize=96&sort=_oldstart&_input_charset=utf-8";
foreach ($cats as $cat) {
    $search_url = $search_res . "&cat={$cat}";
    echo $cat . ":";
    echo "\n";
    foreach ($locnames as $province => $cities) {
        echo $province . ":";
        $result = 0;
        $search_url_p = $search_url . "&loc={$province}";
        $total = calTotal($search_url_p);
        if ($total >= 10000) {
            foreach ($cities as $city) {
                $search_url_c = $search_url . "&loc={$city}";
                $totalNum = calTotal($search_url_c);
                $totalNum = ceil($totalNum / 96);
                if ($totalNum > 100) {
                    $totalNum = 100;
                }
                for ($i = 0; $i < $totalNum; $i++) {
                    $result += getinfo($search_url_c . "&s=" . $i * 96);
                }
            }
        } else {
            $totalNum = ceil($total / 96);
            if ($totalNum > 100) {
                $totalNum = 100;
            }
            for ($i = 0; $i < $totalNum; $i++) {
                $result += getinfo($search_url_p . "&s=" . $i * 96);