日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

QueryList入门

發布時間:2023/12/29 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 QueryList入门 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

QueryList入門

規則庫的編寫

$rules = array('規則名' => array('jQuery選擇器','要采集的屬性'),'規則名2' => array('jQuery選擇器','要采集的屬性'),.......... );

利用編寫的規則庫,收集對應的元素

<?php namespace app\index\controller; //require 'vendor/autoload.php';//導入QueryList的庫 use QL\QueryList;class Index {public function index(){//把采集目標放在html變量中,包含在STR里$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'));//使用QueryList中的Query(參數1 采集內容,參數2 采集規則)方法進行采集,在方法中獲取了data變量$data = QueryList::Query($html,$rules)->data;//打印結果print_r($data);} }

結果

Array ( [0] => Array ( [text] => QueryList官網 其它的一些文本 [link] => http://querylist.cc [img] => http://querylist.com/2.jpg [other] => 其它的一些文本 ) )

采集文章頁

<?php namespace app\index\controller; //require 'vendor/autoload.php';use QL\QueryList;class Index {public function demo2(){// 待采集的頁面地址$url = 'https://www.cnbeta.com/articles/tech/779841.htm';// 采集規則$rules = [// 文章標題'title' => ['.title>h1', 'text'],// 發布日期'date' => ['.meta>span:eq(0)', 'text'],// 文章內容'content' => ['#artibody', 'html']];$data = QueryList::Query($url, $rules)->data;print_r($data);} }

總結

以上是生活随笔為你收集整理的QueryList入门的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。