Recently, many netizens have asked me how to use PHP to crawl news from other websites. At first, I was worried about infringement, so I never made it public. But there are too many people asking. Here I will give you an example - how to grab the news of "Shenzhen Window", just for your reference. Please be aware and don't do anything illegal. Thanks.
Catch the "Technology News" directory code page (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; $iecho $str_ary[ $i];
}
}
?>
Related articles
? How to grab the news of "Shenzhen Window"
Many netizens have come recently Asked me how to use PHP to crawl news from other websites. At first I was worried about infringement, so I never made it public. But there are too many people asking. Here I will give you an example - how to grab the news of "Shenzhen Window", just for your reference. Please be aware and don't do anything illegal. Thanks.
Catch the "Technology News" detailed content code page (readNewsDetail.php):
CTOHome.com Technology News Channel
/*
* ctohome.com Shenzhen News
*/
$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("echo "";
for ($i=4; $iecho "}
echo "";
}
?>
The method of crawling depends on the different original codes. You must carefully analyze the HTML original code of the page you want to crawl beforehand, then find out the rules, and finally write the code. IE's error correction function for HTML syntax is very strong, so as long as the displayed results are correct, it doesn't matter if there are some syntax errors in the captured code.
http://www.bkjia.com/PHPjc/532204.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532204.htmlTechArticleRecently, many netizens have asked me how to use PHP to crawl news from other websites. At first, I was worried about infringement. It has never been made public. But there are too many people asking, here I will give you an example ---- how to grab "...