CURL多线程请求扒取页面信息

PHP CURL多线程扒取页面

     $urlarr = array(
            'url1',
            'url2'
            );
    $mh = curl_multi_init();
    foreach ($urlarr as $i => $url) {
        $conn[$i]=curl_init($url);
        curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);
        curl_multi_add_handle ($mh,$conn[$i]);
    }

    do { $n=curl_multi_exec($mh,$active); } while ($active);
    foreach ($urlarr as $i => $url) {
        $res[$i]=curl_multi_getcontent($conn[$i]);
        curl_close($conn[$i]);
    }

    $reg = '/\/html\/(.*?)html/';   //正则匹配想要的数据
    foreach ($res as $key => $value) {
preg_match_all($reg, $value, $arr[$key],PREG_PATTERN_ORDER);//正则匹配的数据放到$arr中
    }
    var_dump($arr);

你可能感兴趣的:(CURL多线程请求扒取页面信息)