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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

thinkphp5 querylist 爬虫

發布時間:2023/12/29 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 thinkphp5 querylist 爬虫 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

php上手超快的框架querylist4

文檔地址:安裝 - QueryList文檔

安裝tp5.1,composer命令安裝?

composer create-project topthink/think tp5

安裝querylist4(環境php>7.0 )

composer require jaeger/querylist

直接在控制器開擼

搞幾個例子吧:

/*** 采集某頁面所有的圖片*/public function test(){//采集某頁面所有的圖片$data = QueryList::get('http://cms.querylist.cc/bizhi/453.html')->find('img')->attrs('src');//打印結果print_r($data->all());}/*** 多線程*/public function getList(){$urls = ['https://github.com/trending/go?since=daily','https://github.com/trending/html?since=daily','https://github.com/trending/java?since=daily'];QueryList::multiGet($urls)->success(function (QueryList $ql, Response $response, $index) use ($urls) {echo 'Current url: ' . $urls[$index] . "\r\n";$data = $ql->find('h3>a')->texts();print_r($data->all());})->send();}/*** 獲取html*/public function getHtml(){$ql = QueryList::get('http://www.ypyunedu.com/');echo $ql->getHtml();}/*** 獲取表格元素*/public function table(){//獲取html$ql = QueryList::get('https://v3.bootcss.com/css/#tables');$html = $ql->getHtml();$table = QueryList::html($html)->find('table');// 采集表頭$tableHeader = $table->find('tr:eq(0)')->find('td')->texts();// 采集表的每行內容$tableRows = $table->find('tr:gt(0)')->map(function ($row) {return $row->find('td')->texts()->all();});print_r($tableHeader->all());print_r($tableRows->all());}/*** 獲取部分元素*/public function part(){//獲取html$ql = QueryList::get('http://www.ypyunedu.com/');$html = $ql->getHtml();$ql = QueryList::html($html);$rt = [];//獲取第一張圖片的鏈接地址//下面四種寫法完全等價$rt[] = $ql->find('img')->attr('src');$rt[] = $ql->find('img')->src;$rt[] = $ql->find('img:eq(0)')->src;$rt[] = $ql->find('img')->eq(0)->src;//獲取第一張圖片的alt屬性$rt[] = $ql->find('img')->alt;//獲取第一張圖片的abc屬性,注意這里獲取定義屬性的寫法與普通屬性的寫法是一樣的$rt[] = $ql->find('img')->abc;print_r($rt);}

總結

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

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