PHP code example of kiddyu / beanbun-parser

1. Go to this page and download the library: Download kiddyu/beanbun-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kiddyu / beanbun-parser example snippets



use Beanbun\Beanbun;
use Beanbun\Middleware\Parser;

$beanbun = new Beanbun;
$beanbun->name = '950d';
$beanbun->seed = 'http://www.950d.com/';

$parser = new Parser;
$beanbun->middleware($parser);

$beanbun->fields = [
    [
        'name' => 'title',
        'selector' => ['title', 'text']
    ],
    [
        'name' => 'template',
        'children' => [
            [
                'name' => 'title',
                'selector' => ['.js-course-list li h5', 'text'],
                'repeated' => true,
            ],
            [
                'name' => 'url',
                'selector' => ['.js-course-list li .course-list-img a', 'href'],
                'repeated' => true,
            ],
            [
                'name' => 'image',
                'selector' => ['.js-course-list li .course-list-img img', 'src'],
                'repeated' => true,
            ]
        ]
    ]
];

$beanbun->afterDownloadPage = function($beanbun) {
    print_r($beanbun->data);
};

// 上面例子中抽取到的数据为
$beanbun->data = [
    'title' => '企业网站模板 - Finecms模板 Duxcms模板 Doccms模板 稻壳cms模板',
    'template' => [
        'title' => [
            '旅游类通用型手机站模板',
            '简洁高效多产品分类模板',
            '虚拟商品销售网站Doccms模板',
            '幼儿园幼儿教育Doccms网站模板',
            '宠物会馆职业培训类Doccms模板',
            '蓝色物流运输类Doccms模板',
            '设计公司Duxcms手机网站模板',
            '设计公司Duxcms网站模板',
            'Doccms2016版大气简洁企业站模板',
            '响应式红色企业网站模板',
            '投资金融贷款类企业网站模板',
            '投资贷款类企业手机模板'
        ],
        'url' => [
            'http://www.950d.com/list/187.html',
            'http://www.950d.com/list/184.html',
            'http://www.950d.com/list/183.html',
            'http://www.950d.com/list/182.html',
            'http://www.950d.com/list/181.html',
            'http://www.950d.com/list/180.html',
            'http://www.950d.com/list/179.html',
            'http://www.950d.com/list/178.html',
            'http://www.950d.com/list/177.html',
            'http://www.950d.com/list/176.html',
            'http://www.950d.com/list/175.html',
            'http://www.950d.com/list/174.html'
        ],
        'image' => [
            '/upload/2016-12-27/2c41a2b55cc1123a2909487e9c078969.jpg',
            '/upload/2016-11-05/41bac823202e3f8b37dccb285f09b7ca.jpg',
            '/upload/2016-11-05/336269e55db23da60e519d4806f6d2b0.jpg',
            '/upload/2016-11-05/913ed6669b8cf2de0d366c55f0917002.jpg',
            '/upload/2016-11-05/1760bd081855d178e48bd420a42d34d4.jpg',
            '/upload/2016-11-05/614212d8bd4b4b7d2072300edb0e101d.jpg',
            '/upload/2016-11-04/b5a2eae483169a602d6742ab383c772d.jpg',
            '/upload/2016-11-04/62b40db4bd2ee13a0bcf4e49eae166aa.jpg',
            '/upload/2016-03-22/21d397aa278643d7489533827d16bfa2.jpg',
            '/upload/2016-10-12/d09c689ce01a525b631a5b2b56e052bc.jpg',
            '/upload/2016-09-22/c2ad9f776f424309b89ff24bdefd152b.jpg',
            '/upload/2016-09-22/d4b32be547ad65a9fd84a14e45e60180.jpg'
        ]
    ]
];

$beanbun->afterDownloadPage = function($beanbun) {
    $data = $beanbun->parser->getData([
        [
            'name' => 'title',
            'selector' => ['title', 'text']
        ]
    ]);
    print_r($data);
};