后端开发|php教程
php,论坛,采集
后端开发-php教程
dz下载站源码,ubuntu怎么安装邮箱,tomcat 启动两个应用,应用来源 爬虫,php登陆后返回原页,全网曝光seolzw
<?php
// 吴燕军
// -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]*? return $threads[1];
}
//判断该帖子是否存在
function isExits($code){
preg_match(/
指定的主题不存在或已被删除或正在被审核,请返回。 /,$code,$error);
return isset($error[0])?false:true;
}
//获取帖子标题
function getTitle($code){
preg_match(/
[^ ]*/,$code,$title_tmp);
$title = $title_tmp[0];
return $title;
}
//获取帖子作者:
function getAuthor($code){
preg_match(/ .+/,$code,$author_tmp);
$author = strip_tags($author_tmp[0]);
return $author;
}
//获取楼主发表的内容
function getContents($code){
preg_match(/
(.|\r|\n)*? /,$code,$contents_tmp);
$contents = preg_replace(/images\//,/images/,$contents_tmp[0]);
return $contents;
}
//打印帖子标题
function printTitle($title){
echo " 帖子标题: ",strip_tags($title)," ";
}
//输出帖子作者
function printAuthor($author){
echo " 帖子作者: ",strip_tags($author)," ";
}
//打印帖子内容
function printContents($contents){
echo " 作者发表的内容: ",$contents,"
";
}
//错误
function printError(){
echo " ";
}
/*函数列表end---------------------------------------------------------------------------------------------------*/
/*登录论坛 begin*/
$url = /logging.php?action=login;
$postfields=loginfield=username&username=1nject10n& password=xxxxxx&questionid=0&cookietime=315360000& referer=/&loginsubmit=提交;
request($url,$postfields,$cookie_jar,\);
unset($postfields,$url);
/*登录论坛 end*/
/*获取帖子列表(位于第一页的帖子) begin*/
$url = /forumdisplay.php?fid=57;
$code = request($url,\,$cookie_jar,\);
$threadsList = getThreadsList($code);
/*获取帖子列表 end*/
//帖子序列
$rows = 0;
/*循环抓取所有帖子源代码 begin*/
foreach($threadsList as $list){
$url = "/viewthread.php?tid=$list";
if(isExits($code)){
$code = request($url,\,$cookie_jar,\);
$color = $rows%2==0?#00CCFF:#FFFF33;
echo "
";
echo "
第",($rows+1),"贴:
";
$author = getAuthor($code);
printAuthor($author);
$title = getTitle($code);
printTitle($title);
$contents = getContents($code);
printContents($contents);
echo "
";
$rows++;
}
else
printError();
echo "----------------------------------------------------------------------------------------- ";
}
/*抓取源代码 end*/
?>
音乐工作室网站源码,vscode不安装c盘,ubuntu用xrite,tomcat6.0破解,下载github爬虫,php 元数据,全网seo推广如何进行,卡盟资源网站源码,html5微信企业网站模板lzw