网易新闻采集,显示列表和内容

<?php
/**
* 作业A:网易新闻采集,显示列表和内容
*/
 header("Content-type:text/html;Charset=GBK;");
if(!isset($_GET['news'])){
$main_url = 'http://news.163.com/special/00013C0B/shizhengxw.html';
$main_content = file_get_contents($main_url);
 
$c = explode('<div class="right-1 right">',$main_content);
$c = explode('</div>',$c[1]);
$content = $c[0];
preg_match_all('/"http:\/\/news.163.com([^"]*)">([^<]*)<\/a><span>([^<]*)<\/span>/',$content,$match);


if($match){
foreach($match[2] as $k=>$title){
$time=$match[3][$k];

$url=$match[1][$k];
$url=str_replace('http://news.163.com','',$url);
echo '<a href="?news='.urlencode($url).'" target=_blank>'.$title.'</a>'.$time;
echo "<br>\r\n";
 
}
}
 
}else{
if($_GET['news']){
$newsurl = $_GET['news'];
$newsurl = 'http://news.163.com'.$newsurl;
$new_content = file_get_contents($newsurl);
preg_match('@<h1 id="h1title">([^<]+)</h1>@',$new_content,$match);
$title = $match[1];
$c=  explode('<span class="info" style="display:block;">', $new_content);
$c=  explode('<div class="wb-article-sharewraper wb-article-sharewraper-sm" id="wb-article-sharewraper-sm">', $c[1]);
$date=$c[0];
preg_match('@<div id="endText">(.*)</div>@s',$new_content,$match);
//preg_match('@<div id="Cnt-Main-Article-QQ" bossZone="content">(.*)</div>@s',$new_content,$match);
$contents = $match[1];
$content=explode('<span class="left">', $contents);
$content=$content[0];

 
echo '<br><strong>标题:</strong>';
echo $title;
echo '<br><strong>时间:</strong>';
echo $date;
echo '<br><strong>内容:</strong><br>';
echo $content;
}
 
}
?>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值