Exemplo n.º 1
0
function collection($userArr)
{
    global $db, $curl;
    $page = 1;
    while (true) {
        $url = "http://www.jianshu.com/users/{$userArr['name']}/subscriptions?page={$page}";
        $curl->setUrl($url);
        $html = $curl->run();
        $p = '/<h4><a href="\\/collection\\/(.*?)"/';
        preg_match_all($p, $html, $match);
        if (is_array($match[1]) && !empty($match[1])) {
            foreach ($match[1] as $value) {
                $temp = $db->get('collection', '*', array('name' => $value));
                if (!is_array($temp) || empty($temp)) {
                    $id = getCollectionInfo($value);
                    $temp['id'] = $id;
                }
                //关系表
                $temp = $db->get('collection_user_relation', '*', array('AND' => array('cid' => $temp['id'], 'uid' => $userArr['id'])));
                if (!is_array($temp) || empty($temp)) {
                    $db->insert('collection_user_relation', array('cid' => $temp['id'], 'uid' => $userArr['id']));
                }
                $db->clear();
            }
        } else {
            break;
        }
        $page++;
        echo "collection:{$page}\r\n";
    }
}
Exemplo n.º 2
0
function getCollection()
{
    global $curl;
    $page = 1;
    while (true) {
        //热门
        //$url = "http://www.jianshu.com/collections?category_id=53&page={$page}&_=1476265581231";
        //推荐
        //$url = "http://www.jianshu.com/collections?order_by=score&page={$page}&_=1476259795034";
        //城市
        $url = "http://www.jianshu.com/collections?category_id=69&page={$page}&_=1476346480280";
        $curl->setUrl($url);
        $html = $curl->run();
        $p = '/"\\/collection\\/(.*?)\\"/';
        preg_match_all($p, $html, $math);
        if (isset($math[1]) && !empty($math[1])) {
            $temp = array_unique($math[1]);
            //        print_r($temp);
            foreach ($temp as $value) {
                getCollectionInfo($value);
            }
        } else {
            echo "Over!\r\n";
            break;
        }
        $page++;
        echo $page, "\r\n";
    }
}