Heim  >  Artikel  >  Backend-Entwicklung  >  php通过curl添加cookie伪造登陆抓取数据的方法_php技巧

php通过curl添加cookie伪造登陆抓取数据的方法_php技巧

WBOY
WBOYOriginal
2016-05-16 19:54:541451Durchsuche

本文实例讲述了php通过curl添加cookie伪造登陆抓取数据的方法。分享给大家供大家参考,具体如下:

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

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

2、

<&#63;php
header("Content-type:text/html;Charset=utf8");
$ch =curl_init();
curl_setopt($ch,CURLOPT_URL,'http://www.babytree.com/user/picjournal.php');
$header = array();
//curl_setopt($ch,CURLOPT_POST,true);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch,CURLOPT_COOKIE,'B=115.100.62.7.1401937092035530; bdshare_firstime=1401937092199; __myutma=122328856.1548793539.1401937093.1408503164.1408694138.69;');
$content = curl_exec($ch);
echo "<pre class="brush:php;toolbar:false">";print_r(curl_error($ch));echo "
"; echo "
";print_r(curl_getinfo($ch));echo "
"; echo "
";print_r($header);echo "
"; echo "",$content;

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php curl用法总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn