如何抓取“深圳之窗”的新闻
最近不少网友来问我如何用PHP来抓取其他网站的新闻,开始我担心会侵权,一直没公开。但问的人太多了,这里我举个例子 ---- 如何抓取“深圳之窗”的新闻,仅供大家参考使用思路。请大家自觉,不要做违规的事。谢谢。
抓取“科技新闻”目录代码页(readNews.php):
$url = "http://news.szptt.net.cn/kjxw.phtml";
if(isset($url)&&$url!="") {
$str = implode("",file($url));
$str_ary = explode("
- ",$str);
$str_ary = explode("",$str_ary[1]);
for ($i=0; $i<15; $i++) {
echo $str_ary[$i];
}
}
?>
相关文章
? 如何抓取“深圳之窗”的新闻
最近不少网友来问我如何用PHP来抓取其他网站的新闻,开始我担心会侵权,一直没公开。但问的人太多了,这里我举个例子 ---- 如何抓取“深圳之窗”的新闻,仅供大家参考使用思路。请大家自觉,不要做违规的事。谢谢。
抓取“科技新闻”详细内容代码页(readNewsDetail.php):
/*
* ctohome.com 深圳新闻
*/
$url_ary = explode("/",$url);
$url = $url_ary[count($url_ary)-2] . "/" . $url_ary[count($url_ary)-1];
$url = "http://news.szptt.net.cn/" . $url;
if(isset($url)&&$url!="") {
$str = implode("",file($url));
$str_ary = explode("
PHP之友评论