预览模式: 普通 | 列表

Php使用curl模拟浏览器采集网页

Php使用curl模拟浏览器采集网页

PHP代码
  1. <?php   
  2. set_time_limit(0);   
  3. function _rand() {   
  4. $length=26;   
  5. $chars = "0123456789abcdefghijklmnopqrstuvwxyz";   
  6. $max = strlen($chars) - 1;   
  7. mt_srand((double)microtime() * 1000000);   
  8. $string = '';   
  9. for($i = 0; $i < $length$i++) {   
  10. $string .= $chars[mt_rand(0, $max)];   
  11. }   
  12. return $string;   
  13. }   
  14. $HTTP_SESSION=_rand();   
  15. $HTTP_SESSION;   
  16. $HTTP_Server="search.china.alibaba.com";   
  17. $HTTP_URL="/company/k-%CB%AE%CB%AE%CB%AE_n-y.html";   
  18. $ch = curl_init();   
  19. curl_setopt ($ch,CURLOPT_URL,"http://".$HTTP_Server.$HTTP_URL);   
  20. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);   
  21. 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)");   
  22. $res = curl_exec($ch);   
  23. curl_close ($ch);   
  24. print_r($res);   
  25. ?>   

Tags: php curl

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 4768

 广告位

↑返回顶部↑