使用QueyList採集插件採集數據

借鑑地址: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  這個文件

解決:

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章