分类:PHP 发布时间:2016-11-18 11:10:00
**curl爬虫** ``` $curl=curl_init(); curl_setopt ($curl, CURLOPT_URL, "http://5sing.kugou.com/yc/share/more_1.shtml"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $output = curl_exec($curl); curl_close($curl); $output = preg_replace('/\r|\n|\s{2,}/', '', $output); $pattern = '/<h3><a href="(.*)" target="_blank">(.*)<\/a><\/h3>/'; preg_match_all($pattern, $output, $out, PREG_SET_ORDER); echo "<table><tr><th>标题</th><th>链接</th></tr>"; foreach ($out as $key => $value) { echo "<tr>"; echo '<td>'.$value[2].'</td>'; echo '<td>http://5sing.kugou.com'.$value[1].'</td>'; echo "</tr>"; } echo "</table>"; ``` **curl完整测试** 相关参数请参照 <a href='http://php.net/manual/zh/function.curl-setopt.php'>PHP 手册</a> ``` $s = '阿萨德'; $data = [ 'aasd' => 'getDomainList', 'rike' => 'asdasd', 's' => $s, 'uid' => '15032', 'name' => 'www.百度.com' ]; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'https://www.cdnbest.com/api/?c=site&a=getDomainList'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($curl, CURLOPT_REFERER, 'http://php.net/manual/zh/book.curl.php'); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); $output = curl_exec($curl); curl_close($curl); echo "<pre>"; print_r($output); echo "</pre>"; ```
搜索
文章分类
最新文章