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删除!

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