PHP curl模拟浏览器采集阿里巴巴的实现代码
程序员文章站
2023-11-09 22:53:22
没有不可能只有不去做,哈哈 复制代码 代码如下:
没有不可能只有不去做,哈哈
<?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,"http://".$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);
?>
复制代码 代码如下:
<?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,"http://".$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);
?>