php抓取数据
$url = $_POST[‘url‘]; $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $content = curl_exec($ch); curl_close($ch); //处理内容 $str = $content; $start = ‘<div class="buyer_count">‘; $end = ‘</div>‘; $rowtmp = get_sub_content($str, $start, $end); $row = strip_tags(substr(trim($rowtmp),0,-9)); sleep(2);//休息2秒看效果 ob_flush(); flush();
get_sub_content($str, $start, $end){ if ( $start == ‘‘ || $end == ‘‘ ){ return; } $str = explode($start, $str); $str = explode($end, $str[1]); return $str[0]; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。