Using QueryList3 in ThinkPHP
Note: This article is based on ThinkPHP3.2.3
Execute the command directly in the ThinkPHP root directory:
composer require jaeger/querylist
QueryList is installed, and then introduce composer’s automatic loading file in index.php:
<?php // 应用入口文件 //........ //加上下面这一句话,用于自动加载QueryList require 'vendor/autoload.php'; // 引入ThinkPHP入口文件 require './ThinkPHP/ThinkPHP.php'; // 亲^_^ 后面不需要任何代码了 就是如此简单
You can use QueryList in your framework in just these two steps:
<?php namespace Home\Controller; use Think\Controller; use QL\QueryList; class IndexController extends Controller { public function index(){ //采集某页面所有的图片 $data = QueryList::Query('http://cms.querylist.cc/bizhi/453.html',['image' => ['img','src']])->data; //打印结果 print_r($data); } }
thinkphp3.2.3 integrates QueryList3 and all plug-in packaging
Package download: http://source.querylist.cc/Querylist-demo/thinkphp3.2.3_QueryList3_full.zip
Method Two: Manual installation
1. Download
QueryList download address: https://github.com/jae-jae/QueryList
phpQuery download address: https://github.com/jae-jae/phpQuery-single
2. Installation
According to TP official tutorial: http://document.thinkphp.cn/manual_3_2.html#lib_extend
Assume that the root directory of your website is www
List the installation first The finished directory structure:
www └── ThinkPHP ├── Library │ ├── QL │ │ ├── phpQuery.php │ │ └── QueryList.class.php
安装过程:
1.下载`QueryList.php`和`phpQuery.php`这两个文件。
2.在` www/ThinkPHP/Library`下新建`QL`目录。
3.将下载好的`QueryList.php`和`phpQuery.php`这两个文件复制到` www/ThinkPHP/Library/QL`目录。
4.重命名`QueryList.php`为`QueryList.class.php`。
Then you can use QueryList arbitrarily in your framework, but when you run it, you will find that phpQuery is not found. At this time, there are two solutions:
Option one:Manually introduce phpQuery before each use of QueryList
##Option two:Modify the QueryList source code and add the following In a sentence:
require 'phpQuery.php';This way you don’t have to manually introduce
phpQuery every time
3. Use case<?php
namespace Home\Controller;
use Think\Controller;
use QL\QueryList;
class IndexController extends Controller {
public function index(){
//采集某页面所有的超链接
$data = QueryList::Query('http://cms.querylist.cc/bizhi/453.html',['link' => ['a','href']])->data;
//打印结果
print_r($data);
}
}
4. Attached is the compressed package of QueryList manually installed by ThinkPHP Download address :http://source.querylist.cc/Querylist-demo/thinkphp3.2.3_QueryList3_custom.zip