首頁  >  文章  >  後端開發  >  采集论坛程序:模拟登陆,抓取页面_PHP教程

采集论坛程序:模拟登陆,抓取页面_PHP教程

WBOY
WBOY原創
2016-07-13 17:38:00745瀏覽

//    吴燕军
//   2009-06-27
//   采集程序php
set_time_limit(0);

//cookie保存目录
$cookie_jar = /tmp/cookie.tmp;

/*函数------------------------------------------------------------------------------------------------------------*/

//模拟请求数据
function request($url,$postfields,$cookie_jar,$referer){
$ch = curl_init();
$options = array(CURLOPT_URL => $url,
      CURLOPT_HEADER => 0,
      CURLOPT_NOBODY => 0,
      CURLOPT_PORT => 80,
      CURLOPT_POST => 1,
      CURLOPT_POSTFIELDS => $postfields,
      CURLOPT_RETURNTRANSFER => 1,
      CURLOPT_FOLLOWLOCATION => 1,
      CURLOPT_COOKIEJAR => $cookie_jar,
      CURLOPT_COOKIEFILE => $cookie_jar,
      CURLOPT_REFERER => $referer
);
curl_setopt_array($ch, $options);
$code = curl_exec($ch);
curl_close($ch);
return $code;
}

//获取帖子列表
function getThreadsList($code){
preg_match_all(/

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn