ThinkPHP5在PHP7以上使用QueryList4, ThinkCMF在PHP5中使用QueryList3教程

QueryList 是一款用于网页采集爬虫的框架,官方最新版本为QueryList4,QueryList4版本只能在PHP7以上使用;

在PHP7以上环境中,如何在ThinkPHP5中使用QueryList4 ,开发者也给出了教程。对于PHP5环境,只能使用QueryList3,官网给出的ThinkPHP中使用QueryList3的教程,是基于ThinkPHP3.2.3。目前我们用的基本为ThinkPHP5为主,包括ThinkCMF fastAdmin 也都是基于ThinkPHP5的,虽然使用并不复杂,对于刚上手的同学可能会遇到问题,这里写出来以供参考。

PHP7以上安装步骤
下载TP5
去ThinkPHP官网下载最新的ThinkPHP5框架代码: http://www.thinkphp.cn

安装QueryList
在ThinkPHP5代码根目录执行composer命令安装QueryList:

composer require jaeger/querylist
使用QueryList
下面演示在Index控制器中使用QueryList:

<?php
namespace appindexcontroller;
 
use QLQueryList;
 
class Index
{
    public function index()
    {
       //采集某页面所有的图片
       $data = QueryList::get('http://cms.querylist.cc/bizhi/453.html')->find('img')->attrs('src');
       //打印结果
       print_r($data->all());
    }
}
PHP5中,ThinkCMF安装QueryList3步骤
下载QueryList3
QueryList下载地址:https://github.com/jae-jae/QueryList/tree/V3.2.1

phpQuery下载地址:https://github.com/jae-jae/phpQuery-single

下载`QueryList.php`和`phpQuery.php`这两个文件

在ThinkCMF中使用QueryList3
修改QueryList源码,加上下面这句话:

require 'phpQuery.php';
在` www/ThinkCMF/simplewind/extend`下新建`QL`目录,将下载好的`QueryList.php`和`phpQuery.php`这两个文件复制到该目录。

目录结构:

ThinkCMF
└── simplewind
    ├── extend
    │   ├── QL
    │   │   ├── phpQuery.php
    │   │   └── QueryList.php
使用
use QLQueryList;
 
public function index() {
   //采集某页面所有的超链接
      $d = QueryList::Query('http://cms.querylist.cc/bizhi/453.html',['link' => ['a','href']])->data;
      //打印结果
      print_r($d);
 
 
}
 
--------------------- 
版权声明:本文为CSDN博主「丁汤汤」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010035608/article/details/83118391

原文地址:https://www.cnblogs.com/blogpro/p/11339136.html