Пример #1
0
        }
        echo "\n";
    }
} else {
    include_once 'QProxy.php';
    $line = $argv[1];
    $data = array();
    $lineProxy = 0;
    foreach ($QData as $key => &$keyWord) {
        $i = $lineProxy % $line;
        if ($line - 1 == $i) {
            $jsonDir = "{$rootDir}/{$date}/{$key}.json";
            echo "{$key}";
            if (!file_exists($jsonDir)) {
                $isSuccess = null;
                while ($isSuccess != true) {
                    $ctx = stream_context_create(array('http' => array('timeout' => 3, 'proxy' => $QProxy[array_rand($QProxy, 1)], 'request_fulluri' => true)));
                    $direct = QPage::getURL($key, $url['url']);
                    $code = QPage::getHtmlCode($direct, $ctx);
                    // var_dump($code);
                    if ($code != null && stripos($code, '360指数') == false) {
                        file_put_contents($jsonDir, $code);
                        $isSuccess = true;
                    }
                }
            }
            echo "\n";
        }
        $lineProxy++;
    }
}
Пример #2
0
include_once 'QPage.php';
include_once 'QData.php';
include_once 'QUrl.php';
include_once 'config.php';
$date = date('Ymd');
$data = array();
$rootDir = 'result';
foreach ($QData as $key => &$keyWord) {
    $jsonDir = "{$rootDir}/{$date}/{$key}.json";
    if (file_exists($jsonDir)) {
        $code = file_get_contents($jsonDir);
        $r = json_decode($code);
        $result = explode('|', $r->data->index->{$key});
        $data[$key]['id'] = $key;
        $data[$key]['name'] = $keyWord;
        for ($i = 0; $i < 5; $i++) {
            $rowName = 'day' . ($i + 1);
            $data[$key][$rowName] = array_pop($result);
        }
        $data[$key]['url'] = QPage::getURL($key, $QUrl[QPURL]);
    }
}
$dom = new DomDocument('1.0', 'utf-8');
$list = $dom->createElement('list');
$dom->appendchild($list);
foreach ($data as $value) {
    QPage::createItem($dom, $list, array('item' => $value));
}
$xmlDir = "{$rootDir}/{$date}.xml";
$dom->save($xmlDir);
echo "Finish!\n";