Home > Backend Development > PHP Tutorial > PHP collects the reading ranking of CSDN blog sidebar_PHP tutorial

PHP collects the reading ranking of CSDN blog sidebar_PHP tutorial

WBOY
Release: 2016-07-13 10:22:25
Original
975 people have browsed it

PHP collects the reading ranking of CSDN blog sidebar

The collected data will be used in the project, so I tried it on the CSDN blog first. The Simple HTML DOM (official website) library is used here, which can conveniently traverse HTML documents.

PHP collects the reading ranking of CSDN blog sidebar_PHP tutorial
<?php
    include_once('simple_html_dom.php');
    header('Content-Type:text/html;charset=utf-8');
    $html = file_get_html('http://blog.csdn.net/szy361');

    $res = $html->find('#hotarticls ul.panel_body li a[title]');//取得id=hotarticls下class为panel_bodya的ul标签下的a的title
    $span = $html->find('#hotarticls ul.panel_body li span');//取得span
    foreach($res as $element){
        $arr[] = $element->title.'&#43;'.$element->href;//将title&#20540;和href的&#20540;通过&#43;连起来
    }
    foreach($span as $e){
        $brr[] = $e->innertext;//得到span下的&#20540;组成的数组
    }
    
    //将两个数组组成一个新的二维数组
    for($i=0;$i<count($res);$i&#43;&#43;){
        $crr[] = explode('&#43;',$arr[$i]);
        $crr[$i][] = $brr[$i];
    }
    return $crr;
Copy after login
PHP collects the reading ranking of CSDN blog sidebar_PHP tutorial

Extension:

Getting started with PHP Simple HTML DOM parser

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/847858.htmlTechArticlePHP collects the data collected in the CSDN blog sidebar reading ranking project, so let’s take the CSDN blog first Tried it. The library Simple HTML DOM (official website) is used here, which can facilitate...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template