The data to be collected is used in the PHP reading ranking project on the edge bar of the CSDN blog, so we first tried it with the CSDN blog. Here, SimpleHTMLDOM (official website) library is used to easily traverse HTML documents. & Nbsp; & lt ;? Phpinclude_once (simple_html_dom.php); header (Content-Type: texthtml PHP collection CSDN blog sidebar reading ranking
The collected data is used in the project, so we first tried it with the CSDN blog. Here we use the Simple html dom Library, which can easily traverse HTML documents.
Find ('# hotarticls ul. panel_body li a [title] '); // Obtain the title $ span of a under the ul label of class panel_bodya under id = hotarticls = $ html-> find ('# hotarticls ul. panel_body li span '); // Get span foreach ($ res as $ element) {$ arr [] = $ element-> title. '+ '. $ element-> href; // connects the title value and href value through +} foreach ($ span as $ e) {$ brr [] = $ e-> innertext; // Get the array composed of values under span} // combine the two arrays into a new two-dimensional array for ($ I = 0; $ I
Extension:
PHP Simple html dom parser getting started