php实现爬取数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39191303/article/details/82894334

//安装QueryList
composer require jaeger/querylist

<?php
include './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());
// 打印结果

猜你喜欢

转载自blog.csdn.net/qq_39191303/article/details/82894334