querylist php采集工具

本文介绍使用QueryList进行网络爬虫的实际应用,演示了从特定网站抓取律师信息的过程,包括姓名、邮箱、电话等详细数据,并将其存入数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

querylist

案例1

 public function index()
    {
        ini_set('max_execution_time', '0');
        set_time_limit (0);
        $page =Db::name('user')->order('id DESC')->value('page');
        for ($i=$page; $i<=1425; $i++){

            $this->du($i);

        }
    }

    public function du($i){
        $data = QueryList::get('http://www.njslawyers.org/searchLawyer?association=&practiceScope=&gender=&name=&licenseNumber=&practiceOrg=&x=80&y=20&page='.$i)
            ->rules([
                'link'=>array('dt>span>a','href'),
                'page'=>array('.act','text'),
            ])
            ->queryData();
        $page = $data[0]['page'];
        foreach ($data as $key => $value){
            $table = QueryList::get('http://www.njslawyers.org'.$value['link'])->find('table');
            $tableRows = $table->find('tr:eq(2),tr:eq(14)')->map(function($row){
                return $row->find('td:eq(1)')->texts()->all();
            });
            $data1 = $tableRows->all();
            $name =$data1[0][0];
            $email =$data1[1][0];
            $link = $table->find('tr:eq(3)')->map(function($row){
                return $row->find('td:eq(1)>a')->attr('href');
            });
            $phone_link  =$link->all()[0];
            $phone = QueryList::get('http://www.njslawyers.org'.$phone_link) ->rules([
                'phone'=>array('dd:eq(4)','text'),
            ])->queryData();
            $phone = (isset($phone[0]['phone']))?$phone[0]['phone']:'';


            Db::name('user')->insert(['name'=>$name,'mobile'=>$phone,'email'=>$email,'page'=>$page]);

        }
        return $page;
    }

案例2

 public function index()
    {
        ini_set('max_execution_time', '0');
        set_time_limit (0);
        $page =Db::name('user')->order('id DESC')->value('page')??0;
        $page++;
        for ($i=$page; $i<=484; $i++){
            $this->du($i);
        }

    }

    public function du($i){
        $html = QueryList::get('http://sx.sxlsw.org/lvshiS.aspx?page='.$i);
        $table=$html->find('table');
        $page = $html->find('.hover')->text();
        $tabledata = $table->find('tr:gt(3)')->map(function($row){
            return $row->find('td>a')->attr('href');
        });
        foreach ($tabledata as $key => $value){
            $tabledata = QueryList::get('http://sx.sxlsw.org'.$value)->find('table');
            $tableRows = $tabledata->find('tr:eq(0),tr:eq(3),tr:eq(4)')->map(function($row){
                return $row->find('td:eq(1),td:eq(3)')->texts()->all();
            });
            $data = $tableRows->all();
            $name = isset($data[0][0])?$data[0][0]:'';
            $email = isset($data[1][1])?$data[1][1]:'';
            $phone = isset($data[2][0])?$data[2][0]:'';
            Db::name('user')->insert(['name'=>$name,'mobile'=>$phone,'email'=>$email,'page'=>$page]);
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值