php抓取新浪新闻,新浪新闻采集程序
利用正則表達式提取內容信息<?php
//error_reporting(0);
$date=date("Ymd");
//echo $date;
$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";
$doc=file_get_contents($url);
header("Content-Type:text/html;charset=gb2312");//UNICODE轉GB2312
//echo $doc;
preg_match_all('/"url":".*l/U',$doc,$article);//獲取文章列表
$article=current($article);//二維數組轉一維數組
//print_r($article);
$rule="/\"url\":(.*)\"\"/";
function OnlyUrl($string){
$string=stripslashes($string);
$string=str_replace('"url":"',"",$string);
return $string;
}
function GetTitle($url){ //獲取文章標題
$doc=file_get_contents($url);
$rule="/
/";
preg_match($rule,$doc,$result);
echo $result;
}
foreach($article as &$value){
$value=OnlyUrl($value);
}//提取了URL
?><?php
function GetTitle($url){ //獲取文章標題
$rule="/
/";
preg_match_all($rule,$doc,$result);
$rule="/>(.*)";//截掉
preg_match($rule,$result[0][1],$title);
return $title[1];
}
function GetContent($url){
$doc=file_get_contents($url);//打開網頁
// echo $doc;
$rule="/publish_helper(.*)publish_helper_end/xs";
preg_match($rule,$doc,$result);//取出正文部分
//echo $result[0];
$rule="/publish_helper(.*)/xs";
preg_match($rule,$result[0],$out);//取出鏈接部分
//print_r($out);
$content=str_replace($out[0],"",$result[0]);//提取純文字段的內容
echo $content;
}
?>
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的php抓取新浪新闻,新浪新闻采集程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 光谱分类算法 matlab,Matlab
- 下一篇: matlab散点拟合系数,matlab离