首页 >后端开发 >php教程 >php curl 添加cookie伪造登陆抓取数据

php curl 添加cookie伪造登陆抓取数据

WBOY
WBOY原创
2016-07-25 08:42:101001浏览

有的网页必须登陆才能看到,这个时候想要抓取信息必须在header里面传递cookie值才能获取


1、首先登陆网站,打开firebug就能看到对应的cookie把这些cookie拷贝出来就能使用了



2、

  1. header("Content-type:text/html;Charset=utf8");
  2. $ch =curl_init();
  3. curl_setopt($ch,CURLOPT_URL,'http://www.babytree.com/user/picjournal.php');
  4. $header = array();
  5. //curl_setopt($ch,CURLOPT_POST,true);
  6. //curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  7. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  8. curl_setopt($ch,CURLOPT_HEADER,true);
  9. curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  10. curl_setopt($ch,CURLOPT_COOKIE,'B=115.100.62.7.1401937092035530; bdshare_firstime=1401937092199; __myutma=122328856.1548793539.1401937093.1408503164.1408694138.69;');
  11. $content = curl_exec($ch);
  12. echo "
    ";print_r(curl_error($ch));echo "
    ";
  13. echo "
    ";print_r(curl_getinfo($ch));echo "
    ";
  14. echo "
    ";print_r($header);echo "
    ";
  15. echo "",$content;
复制代码

php, curl, cookie


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn