phpspider框架的使用

手册:https://doc.phpspider.org/configs-members.html

参考:https://www.jianshu.com/p/01052508ea7c

不多说,代码贴上:

<?php
require './vendor/autoload.php';
use phpspider\core\phpspider;

/* Do NOT delete this comment */
/* 不要删除这段注释 */


$configs = array(
    'name' => '简书',
    'log_show' =>false,
    'tasknum' => 1,

    'log_file' => 'data/qiushibaike.log',

    'log_type' => 'error,debug,warn',

//数据库配置
    'db_config' => array(
        'host'  => '127.0.0.1',
        'port'  => 3306,
        'user'  => 'pai',
        'pass'  => 'pai',
        'name'  => 'pai',
    ),

//导出数据到Mysql
    'export' => array(
        'type' => 'db',
        'table' => 'pai_content',  // 如果数据表没有数据新增请检查表结构和字段名是否匹配
    ),

//爬取的域名列表
    'domains' => array(
        'jianshu',
        'www.jianshu.com'
    ),

//定义爬虫的入口链接, 爬虫从这些链接开始爬取,同时这些链接也是监控爬虫所要监控的链接(入口)
    'scan_urls' => array(
        'https://www.jianshu.com'
    ),

//定义列表页url的规则(列表)
    'list_url_regexes' => array(
        "https://www.jianshu.com"
    ),

//定义内容页url的规则content_url_regexes
    'content_url_regexes' => array(
        "https://www.jianshu.com/p/\w+",
    ),

    'max_try' => 1,

    'fields' => array(
        array(
            'name' => "title",
            'selector' => "//h1[@class='_1RuRku']",
            'required' => true,
        ),
        array(
            'name' => "content",
            'selector' => "//article[@class='_2rhmJa']",
            'required' => true,
        ),
    ),
);

$spider = new phpspider($configs);
$spider->start();

 

转载于:https://www.cnblogs.com/laijinquan/p/11468952.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值