Recently, many netizens have asked me how to use PHP to capture news from other websites. at first, I began to worry about infringement and have never been made public. However, there are too many people to ask. here is an example-how to capture the "Shenzhen Window" news for your reference only. Do not violate regulations. Thank you. Capture "technology SyntaxHighlighter. all ();
Recently, many netizens have asked me how to use PHP to capture news from other websites. at first, I began to worry about infringement and have never been made public. However, there are too many people to ask. here is an example-how to capture the "Shenzhen Window" news for your reference only. Do not violate regulations. Thank you.
Capture the "Tech 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; $ I <15; $ I ++ ){
Echo $ str_ary [$ I];
}
}
?>
Related articles
? How to capture the "Shenzhen Window" news
Recently, many netizens have asked me how to use PHP to capture news from other websites. at first, I began to worry about infringement and have never been made public. However, there are too many people to ask. here is an example-how to capture the "Shenzhen Window" news for your reference only. Do not violate regulations. Thank you.
Capture the "Tech 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; $ I <6; $ I ++ ){
Echo" }
Echo" ";
}
?>
The crawling method depends on the original code. in advance, you must carefully analyze the HTML original code of the page you want to crawl, find out the rules, and finally write the code. IE has a strong error correction function for HTML syntax. Therefore, as long as the result is displayed correctly, it does not matter if the captured code has some syntax errors.