找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 8124|回复: 1

新浪爱问采集

[复制链接]
发表于 2009-11-29 01:43:50 | 显示全部楼层 |阅读模式 IP:江苏扬州
<?php
$text=open('gettemp.php');
if(!$text)
{
$url = 'http://iask.sina.com.cn/browse/i_questionList.php?cid=3&start=140&status=R&num=20&t=1203908584540&_=';
$text=geturl($url);
}
$text = str_replace(chr(92),'%',$text);
$text = str_replace(chr(34),'',unescape($text));
preg_match_all("/qid:(.*?),qclsname/s",$text,$url);
$text='';
foreach($url[1] as $s)
{
$file2='http://iask.sina.com.cn/b/'.$s.'.html';
echo $file2;
$text=clear(geturl($file2));
$text=cut('href=/ class=a05>知识人','<b>我来回答</b></legend>',$text);
// echo $text;
$quarr = getquestion($text);
//print_r($quarr);
$anarr = getanser($text);
print_r($anarr);
$userarr = getuser($text);
break;
//这里没写
}
//取出问
function getquestion($str)
{
if(!empty($str))
{
   $qtitle=cut('<b class=f14 c3>','</b> </td>',$str);
   $qcontent=cut('<tr><td class=f14 lh13 style=padding-right:65px;>','<table border=0 width=100%',$str);
   $arr=array(
    'qtitle' => $qtitle,
    'qcontent' => $qcontent
    );
   return $arr;
}
else
{
   return false;
}
}
//取出答案
function getanser($str)
{
if(!empty($str))
{
   preg_match_all("/<td class=f14 lh15 style=padding-right:65px;>(.*?)<\/td><\/tr><\/table>/s",$str,$c);
   return $c[1];
}
else{
   return false;
}
}
//取出用户
function getuser($str)
{
if(!empty($str))
{
}
else
{
   return false;
}
}
//去悼" '二个坏东西
function clear($str)
{
if(!empty($str))
{
   $str=str_replace(chr(34),'',$str);
   $str=str_replace(chr(39),'',$str);
   return $str;
}
else
{
   return false;
}
}
//--------------截取
function cut($from,$end,$file){
$message=explode($from,$file);
$message=explode($end,$message[1]);
return $message[0];
}
//取数
function geturl($url)
{
if(function_exists( "file_get_contents" ))
{
$text = @file_get_contents($url);
}
else
{
$file = @file($url);
if(!empty($file) && is_array($file)){
$text = explode('',$file);
}
}
return $text;
}
//读入
function open($file){
if(is_file($file))
{
$dh=fopen($file,'rb');
$tt=fread($dh,filesize($file));
fclose($dh);
return $tt;
}
else{
return false;
}
}
//写入
function write($str){
if(!empty($str))
{
$file='gettemp.php';
$dh=fopen($file,'wb');
fwrite($dh,$str);
fclose($dh);
return true;
}else{
return false;
}
}
//---------------------------------unescape
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|&#x.{4};|&#\d+;|&#\d+?|.+/U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == "&#x")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == "&#") {
$ar[$k] = iconv("UCS-2","GBK",pack("n",preg_replace("/[^\d]/","",$v)));
}
}
return join("",$ar);
}
?>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-29 21:23 , Processed in 0.283320 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表