Recently many netizens came to ask me how to use PHP to crawl other web site news, I began to worry about infringement, has not been public. But asked too many people, here I give an example----how to crawl "Shenzhen window" news, for everyone to refer to the use of ideas. Please be aware that you do not violate the rules. Thank you.
Crawl "Tech News" Catalog 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; $i <15; $i + +) {
echo $str _ary[$i];
}
}
?>
Related articles
? How to crawl the "windows of Shenzhen" news
Recently many netizens came to ask me how to use PHP to crawl other web site news, I began to worry about infringement, has not been public. But asked too many people, here I give an example----how to crawl "Shenzhen window" news, for everyone to refer to the use of ideas. Please be aware that you do not violate the rules. Thank you.
Crawl "tech News" detail code page (readnewsdetail.php):
<title>Ctohome.com Technology news Channel</title>
/*
* 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 (" ";
for ($i =4; $i <6; $i + +) {
echo " }
Echo "
http://www.bkjia.com/phpjc/532204.html www.bkjia.com true http://www.bkjia.com/phpjc/532204.html techarticle recently many netizens to ask me how to use PHP to crawl other web site news, I began to worry about infringement, has not been public. But there are too many people to ask, here I give an example----how to crawl "...
-
echo" "; } ?> The method to crawl depends on the different original code, before you carefully analyze the page you want to crawl HTML original code, and then find the rules, and finally write code. IE has a strong error-correcting function for HTML syntax, so as long as the display results are correct, there are some grammatical errors in the crawled code.