PHP 用CURL POST后获取cookis并使用获取的cookis,在抓取内容 50
例如:网址获取cookis码:Cookie:__cfduid=d10004189f56b7b1b10476b52f1348e361445765815;PHPSESSID=...
例如:
网址获取cookis码:
Cookie:__cfduid=d10004189f56b7b1b10476b52f1348e361445765815; PHPSESSID=5tqjddj89oqgq025e89jp9kq05
二次抓取连接:
http://网址/id.php?id=5tqjddj89oqgq025e89jp9kq0
----------------------------------------------------------------------
到网址获取cookis码
PHPSESSID码作为连接id再次抓取该链接的全部内容,抓取时使用的cookie是网址之前获取的cookie
大概就这样了,希望哪位可以帮忙写一下,先谢谢了 展开
网址获取cookis码:
Cookie:__cfduid=d10004189f56b7b1b10476b52f1348e361445765815; PHPSESSID=5tqjddj89oqgq025e89jp9kq05
二次抓取连接:
http://网址/id.php?id=5tqjddj89oqgq025e89jp9kq0
----------------------------------------------------------------------
到网址获取cookis码
PHPSESSID码作为连接id再次抓取该链接的全部内容,抓取时使用的cookie是网址之前获取的cookie
大概就这样了,希望哪位可以帮忙写一下,先谢谢了 展开
展开全部
用这个。
public function post($url, $post_data) {
$this->_ch = curl_init();
curl_setopt($this->_ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0');
curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($this->_ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($this->_ch, CURLOPT_HEADER, 0);
curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($this->_ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt($this->_ch, CURLOPT_ENCODING, "" );
curl_setopt($this->_ch, CURLOPT_POST, TRUE);
curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($this->_ch, CURLOPT_COOKIEFILE, getcwd () . '/cookie' );
curl_setopt($this->_ch, CURLOPT_COOKIEJAR, getcwd () . '/cookie' );
curl_setopt($this->_ch, CURLOPT_URL, $url);
$this->_body = curl_exec($this->_ch);
$this->_info = curl_getinfo($this->_ch);
$this->_error = curl_error($this->_ch);
curl_close($this->_ch);
}
public function post($url, $post_data) {
$this->_ch = curl_init();
curl_setopt($this->_ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0');
curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($this->_ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($this->_ch, CURLOPT_HEADER, 0);
curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($this->_ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt($this->_ch, CURLOPT_ENCODING, "" );
curl_setopt($this->_ch, CURLOPT_POST, TRUE);
curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($this->_ch, CURLOPT_COOKIEFILE, getcwd () . '/cookie' );
curl_setopt($this->_ch, CURLOPT_COOKIEJAR, getcwd () . '/cookie' );
curl_setopt($this->_ch, CURLOPT_URL, $url);
$this->_body = curl_exec($this->_ch);
$this->_info = curl_getinfo($this->_ch);
$this->_error = curl_error($this->_ch);
curl_close($this->_ch);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询