第五步:设定业务规则

1、首先切换到应用配置目录:
cd Application/Spider/Weather/Config/
2、回过头来重新编辑 main.php:

假定业务需求是:抓取未来7天之内的天气预报,所以设定好业务规则并删除冗余代码后的简化代码如下:

return array(
     'task_init' =>  array(
        'url' => "http://www.weather.com.cn/weather/101010100.shtml",
        "rule" => array(
            'time' => ['div#7d ul.t.clearfix h1',      'text'],
            'wea'  => ['div#7d ul.t.clearfix p.wea',   'text'],
            'tem'  => ['div#7d ul.t.clearfix p.tem',   'text'],
            'wind' => ['div#7d ul.t.clearfix p.win i', 'text'],
        ),  
        'rule_name' => 'r1',
    )
);

results matching ""

    No results matching ""