当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP 模拟浏览器 CURL 采集阿里巴巴

PHP 模拟浏览器 CURL 采集阿里巴巴

2019年06月15日  | 移动技术网IT编程  | 我要评论

 都说阿里巴巴有不能采集和防采集的神话,今天就用张老师讲的curl采集写了一个模拟的代码。没有不可能只有不去做,哈哈

<?php

set_time_limit(0);

function _rand() {

$length=26;

$chars = "0123456789abcdefghijklmnopqrstuvwxyz";

$max = strlen($chars) - 1;

mt_srand((double)microtime() * 1000000);

$string = ;

for($i = 0; $i < $length; $i++) {

$string .= $chars[mt_rand(0, $max)];

}

return $string;

}

$http_session=_rand();

$http_session;

$http_server="search.china.alibaba.com";

$http_url="/company/k-%cb%ae%cb%ae%cb%ae_n-y.html";

$ch = curl_init();

curl_setopt ($ch,curlopt_url,"https://".$http_server.$http_url);

curl_setopt($ch,curlopt_returntransfer,true);

curl_setopt($ch,curlopt_useragent,"mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; sv1; .net clr 1.1.4322; .net clr 2.0.50727)");

$res = curl_exec($ch);

curl_close ($ch);

print_r($res);

 

?>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网