PHP實現爬取數據



//安裝QueryList
composer require jaeger/querylist<?phpinclude './vendor/autoload.php';
// 使用composer安裝後引入目錄
use QL\QueryList;
// 使用插件
$html = file_get_contents('https://www.biqudu.com/14_14778/');
// 手動獲取頁面
$data = QueryList::html($html);
// 得到頁面內容
$data = QueryList::setHtml('https://www.biqudu.com/14_14778/');
// 等同於上面的
html()$data->rules([     // 採集所有a標籤的href屬性  
  'link' => ['a','href'],   
   // 採集所有a標籤的文本內容   
    'text' => ['a','text']    ]);
    // 此處$data = 上面已經獲取到網頁內容之後的對象
    // 設置採集規則/ 替代了傳統正則
    $data->query();
    // 此處$data = 上面已經獲取到網頁內容之後的對象 
    // query 執行操作$data->getData();
    // 此處$data = 上面已經獲取到網頁內容之後的對象
    // 得到數據結果
    $data->all();// 此處
    $data = 上面已經獲取到網頁內容之後的對象// 將數據轉換成二維數組
    print_r($data->all());// 打印結果

本文轉載於https://blog.csdn.net/qq_39191303/article/details/82894334?utm_source=app
如有冒犯,請聯繫qq861337504刪除!

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