用phpQuery简单实现网页内容爬虫
安装方法:
composer require jaeger/querylist
用法:
$phpQuery = \phpQuery::newDocumentFile($url);
$result = \phpQuery::pq('.art_content', $phpQuery);//.art_content 节点
$string = $result->text();//节点文本内容
$html = $result->html();//节点HTML代码
可以通过这个方法实现一个简单的网页爬虫,抓取HTML节点代码
以简书为例,爬取一篇文章内容
$phpQuery = \phpQuery::newDocumentFile("https://www.jianshu.com/p/0c856519824d");
$title = \phpQuery::pq('title', $phpQuery)->text();//网页title
$content = \phpQuery::pq('.show-content', $phpQuery)->html();//文章内容节点
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有