一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

php 論壇采集程序 模擬登陸,抓取頁面 實現代碼

復制代碼 代碼如下:
<?php
// 吳燕軍
// 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('/ <!--[.|/r|/n]*? <a href=/"viewthread.php/?tid=(/d+)/',$code,$threads);
return $threads[1];
}
//判斷該帖子是否存在
function isExits($code){
preg_match('/ <p>指定的主題不存在或已被刪除或正在被審核,請返回。 <//p>/',$code,$error);
return isset($error[0])?false:true;
}
//獲取帖子標題
function getTitle($code){
preg_match('/ <h1>[^ <//h1>]*/',$code,$title_tmp);
$title = $title_tmp[0];
return $title;
}
//獲取帖子作者:
function getAuthor($code){
preg_match('/ <a href=/"space.php/?uid=/d+/" target=/"_blank/" id=/"userinfo/d+/" onmouseover=/"showMenu/(this/.id/)/">.+/',$code,$author_tmp);
$author = strip_tags($author_tmp[0]);
return $author;
}
//獲取樓主發表的內容
function getContents($code){
preg_match('/ <div id=/"postmessage_/d+/" class=/"t_msgfont/">(.|/r|/n)*? <//div>/',$code,$contents_tmp);
$contents = preg_replace('/images///','http://bbs.war3.cn/images/',$contents_tmp[0]);
return $contents;
}
//打印帖子標題
function printTitle($title){
echo " <strong> <h2>帖子標題: </h2> </strong>",strip_tags($title)," <br/> <br/>";
}
//輸出帖子作者
function printAuthor($author){
echo " <strong> <h2>帖子作者: </h2> </strong>",strip_tags($author)," <br/> <br/>";
}
//打印帖子內容
function printContents($contents){
echo " <strong> <h2>作者發表的內容: </h2>",$contents," </strong> <br/>";
}
//錯誤
function printError(){
echo " <i>該帖子不存在! </i>";
}
/*函數列表end---------------------------------------------------------------------------------------------------*/
/*登錄論壇 begin*/
$url = 'http://bbs.war3.cn/logging.php?action=login';
$postfields='loginfield=username&username=1nject10n& password=xxxxxx&questionid=0&cookietime=315360000& referer=http://bbs.war3.cn/&loginsubmit=提交';
request($url,$postfields,$cookie_jar,'');
unset($postfields,$url);
/*登錄論壇 end*/
/*獲取帖子列表(位于第一頁的帖子) begin*/
$url = 'http://bbs.war3.cn/forumdisplay.php?fid=57';
$code = request($url,'',$cookie_jar,'');
$threadsList = getThreadsList($code);
/*獲取帖子列表 end*/
//帖子序列
$rows = 0;
/*循環抓取所有帖子源代碼 begin*/
foreach($threadsList as $list){
$url = "http://bbs.war3.cn/viewthread.php?tid=$list";
if(isExits($code)){
$code = request($url,'',$cookie_jar,'');
$color = $rows%2==0?'#00CCFF':'#FFFF33';
echo " <div style='background-color:$color'>";
echo " <h1>第",($rows+1),"貼: </h1> <br/>";
$author = getAuthor($code);
printAuthor($author);
$title = getTitle($code);
printTitle($title);
$contents = getContents($code);
printContents($contents);
echo " </div>";
$rows++;
}
else
printError();
echo "----------------------------------------------------------------------------------------- <br/> <br/>";
}
/*抓取源代碼 end*/
?>

php技術php 論壇采集程序 模擬登陸,抓取頁面 實現代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 狠婷婷| 久久机热这里只有精品无需 | 91激情在线 | 国产在线91精品 | 欧美zooz人禽交免费观看 | 国产在线毛片 | 国产色视频一区二区三区 | 国产日韩精品一区在线不卡 | 韩国一级永久免费观看网址 | 91亚洲成人 | 色噜噜狠狠一区二区三区果冻 | 精品四虎免费观看国产高清 | 日本一区二区高清免费不卡 | 色多多www视频在线观看免费 | 国产欧美精品专区一区二区 | 色视频网站大全免费 | 天天做天天爱天天爽综合区 | 夜夜五月天| 色视频网址 | 国产岛国 | 欧美另类xxx精品人妖 | 国产123 | 国产综合色精品一区二区三区 | 国产精品第3页 | 亚洲免费人成 | 高清免费久久影院 | 亚洲第一色图 | 精品久久影院 | 久久一本色系列综合色 | 久久综合九色综合97婷婷女人 | 亚洲国产爱 | 第四色网页| 亚洲第一综合网 | 91视频麻豆 | 六月婷婷综合激情 | 黄网在线播放 | 国产真实乱子伦精品视手机观看 | 人人做人人爽人人爱秋霞影视 | 国产成人精品系列在线观看 | 国产高清美女一级a毛片久久 | 国产91播放 |