本文實例講述了php通過curl添加cookie偽造登陸抓取數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:
有的網(wǎng)頁必須登陸才能看到,這個時候想要抓取信息必須在header里面?zhèn)鬟fcookie值才能獲取
1、首先登陸網(wǎng)站,打開firebug就能看到對應的cookie把這些cookie拷貝出來就能使用了
2、
<?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>";print_r(curl_error($ch));echo "</pre>";
echo "<pre>";print_r(curl_getinfo($ch));echo "</pre>";
echo "<pre>";print_r($header);echo "</pre>";
echo "</br>",$content;
希望本文所述對大家PHP程序設計有所幫助。