免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3139 | 回复: 1
打印 上一主题 下一主题

新浪新闻采集程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-07-02 09:57 |只看该作者 |倒序浏览
[PHP]代码
  1. <?php
  2.     //error_reporting(0);
  3.     $date=date("Ymd");
  4.     //echo $date;
  5.     $url="http://top.finance.sina.com.cn/ws/GetTopDataList.php?top_type=day&top_cat=all&top_time=".$date."&top_show_num=20&top_order=ASC";
  6.     $doc=file_get_contents($url);
  7.     header("Content-Type:text/html;charset=gb2312");//UNICODE转GB2312
  8.     //echo $doc;
  9.     preg_match_all('/"url":".*l/U',$doc,$article);//获取文章列表
  10.     $article=current($article);//二维数组转一维数组
  11.     //print_r($article);
  12.     $rule="/\"url\":(.*)\"\"/";
  13.     function OnlyUrl($string){
  14.        $string=stripslashes($string);
  15.        $string=str_replace('"url":"',"",$string);
  16.        return $string;
  17.     }
  18.      
  19.     function GetTitle($url){  //获取文章标题
  20.       $doc=file_get_contents($url);
  21.       $rule="/<h1 (.*)<\/h1>/";
  22.       preg_match($rule,$doc,$result);
  23.       echo $result;
  24.     }
  25.     foreach($article as &$value){
  26.         $value=OnlyUrl($value);
  27.     }//提取了URL
  28. ?>
  29. <?php
  30.   function GetTitle($url){  //获取文章标题
  31.     $rule="/<h1 (.*)<\/h1>/";
  32.     preg_match_all($rule,$doc,$result);
  33.     $rule="/>(.*)</";//截掉<h1></h1>
  34.     preg_match($rule,$result[0][1],$title);
  35.     return $title[1];
  36.   }
  37.   function GetContent($url){
  38.     $doc=file_get_contents($url);//打开网页
  39.   // echo $doc;
  40.     $rule="/publish_helper(.*)publish_helper_end/xs";
  41.     preg_match($rule,$doc,$result);//取出正文部分
  42.     //echo $result[0];
  43.     $rule="/publish_helper(.*)<\/blockquote>/xs";
  44.     preg_match($rule,$result[0],$out);//取出链接部分
  45.     //print_r($out);
  46.     $content=str_replace($out[0],"",$result[0]);//提取纯文字段的内容
  47.     echo $content;
  48.   }
  49. ?>
复制代码

论坛徽章:
59
2015七夕节徽章
日期:2015-08-24 11:17:25ChinaUnix专家徽章
日期:2015-07-20 09:19:30每周论坛发贴之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38荣誉版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年纪念徽章
日期:2015-07-20 11:05:27IT运维版块每日发帖之星
日期:2015-07-20 11:05:34操作系统版块每日发帖之星
日期:2015-07-20 11:05:36程序设计版块每日发帖之星
日期:2015-07-20 11:05:40数据库技术版块每日发帖之星
日期:2015-07-20 11:05:432015年辞旧岁徽章
日期:2015-07-20 11:05:44
2 [报告]
发表于 2015-07-10 10:10 |只看该作者
采集哪些新闻啊。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP