借鉴地址:https://www.php.cn/php/php-QueyList-kaishi.html
https://www.cnblogs.com/richerdyoung/p/11765206.html
环境:phpstudy 7.3 编辑器sublime apache2.4.39
直接开撸:
1.安装composer (省略)
2./WWW/目录下新建一个index.php文件
3.安装插件
composer require jaeger/querylist
4.index.php文件代码
<?php
require 'vendor/autoload.php';
use QL\QueryList;
$html = <<<STR
<div id="one">
<div class="two">
<a href="http://querylist.cc">QueryList官网</a>
<img src="http://querylist.com/1.jpg" alt="这是图片">
<img src="http://querylist.com/2.jpg" alt="这是图片2">
</div>
<span>其它的<b>一些</b>文本</span>
</div>
STR;
$rules = array(
//采集id为one这个元素里面的纯文本内容
'text' => array('#one','text'),
//采集class为two下面的超链接的链接
'link' => array('.two>a','href'),
//采集class为two下面的第二张图片的链接
'img' => array('.two>img:eq(1)','src'),
//采集span标签中的HTML内容
'other' => array('span','html')
);
$data = QueryList::Query($html,$rules)->data;
print_r($data);
5.出现报错
The each() function is deprecated. This message will be suppressed on further calls
原因:phh7.2以上废除了each方法
解决办法:找到vendor\jaeger\querylist\QueryList.php 这个文件
解决: