• ----:)欢迎访问源码网(:----
    • 首页
    • 博客
    • 学院
    • 下载
    • 论坛
    • 影视
    • 发布源码
    • RSS
    • ITPig
    • 笑话网
    • 百家姓
    • 繁體中文

源码网 - 中国第一源码门户
选择镜像:网通镜像 - 电信主站
  • 首 页
  • 新闻动态
  • 网站运营
  • 网页制作
  • WEB开发
  • 编程开发
  • 图像媒体
  • 操作系统
  • 数据库
  • 服务器
热门搜索 优化 SEO 故事 cms IIS7 MySQL 个人 AdSense 主题推广 | 文章搜索: 高级搜索
会员登录/控制面版您的位置: 学院首页 >> WEB开发 >> PHP 开发 >> PHP代码 >> 详细内容
 

推荐文章

 
 

热点文章

  • 3389远程服务器GHOST的视频教程
  • 利用纯真QQIP数据库做快速IP归属地查询
  • 天气预报小偷,根据IP自动判断地址
  • php在线文本编辑器
  • 实例(Smarty+FCKeditor新闻系统)
  • php生成会动的gif图片代码
  • php里实现汉字转区位码
  • DIV+CSS+PHP巨献——网页内容先竖排再横排
  • php的字符编码转换工具
  • 对dvbbs.php 全文搜索的完全分析
  • PHP获取网卡的MAC地址
  • 56.com视频采集接口程序(PHP)
 
 

相关文章

  • 用PHP控制您的浏览器cache
  • 一个简单的php在线端口扫描器
  • php的curl实现get和post
  • php DOC类型注释的用法
  • 用PHP将mysql数据表转换为excel文件格式
  • ajax+php鼠标拖动层至任意位置并实时保存
  • Tsys CMS For PHP 2.0 系统 发布 和 安装
  • 微软为PHP提供的SQL Server 2005驱动
  • 用PHP和PEAR的Net_GeoIP定位用户
  • php写得javascript类,封装常用js功能
  • PHP中引号的使用
  • PHP5.3中新增的魔术常量__DIR__
 
 

百度搜索

 
 

使用php的curl采集diszuz论坛

  • 阅览次数:
  • 文章来源: CP整理
  • 原文作者:
  • 整理日期: 2008-10-10
  • 发表评论
  • 字体大小:
  • 小
  • 中
  • 大

使用php的curl采集diszuz论坛
写了个diszuz采集论坛的小程序。里面包括了模拟登录,获取页面源代码,正则匹配结果等部分,希望对大家有用。

<?
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://www.eb163.com/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://www.eb163.com/logging.php?action=login';
$postfields='loginfield=username&username=1nject10n&password=xxxxxx&questionid=0&cookietime=315360000&referer=http://www.eb163.com/&loginsubmit=提交';
request($url,$postfields,$cookie_jar,'');
unset(
$postfields,$url);
/*登录论坛 end*/

/*获取帖子列表(位于第一页的帖子) begin*/
$url = 'http://www.eb163.com/forumdisplay.php?fid=57';
$code = request($url,'',$cookie_jar,'');
$threadsList = getThreadsList($code);
/*获取帖子列表 end*/
//帖子序列
$rows = 0;
/*循环抓取所有帖子源代码 begin*/
foreach($threadsList as $list){
$url = "[url=http://www.eb163.com/viewthread.php?tid=$list]http://www.eb163.com/viewthread.php?tid=$list[/url]";
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控制您的浏览器cache
下一篇:《第一财经周刊》:捅破下载软件公司的盈利窗户纸
  • 网友评论:
  • 查看所有评论
  • 我要发表评论
您的网名:
留言主题:
你要发表的内容:

 

关于本站 | 广告联系 | 版权声明 | 网站地图 | 发布软件 | 帮助中心 | 源码论坛

Copyright © 2005-2007 CodePub.Com  程序支持:木翼  滇ICP备05005971号