定制 aprillins/litegrabber 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aprillins/litegrabber

最新稳定版本:1.2

Composer 安装命令:

composer require aprillins/litegrabber

包简介

Grab content from a website using DOMXPath class in PHP

README 文档

README

LiteGrabber is a simple website content scrapper that utilizing the default PHP DOMXPath class.

Installation

You can install LiteGrabber using Composer.

composer require aprillins/litegrabber:dev-master

Then, update your package.

composer update

Don't forget to execute composer dumpautoload after the installation.

Usage

Using LiteGrabber is tremendously easy. Scrapping can be done with three simple step. First, create the LiteGrabber instance.

$liteGrabber = new LiteGrabber($url);

Second, create the query for which element you want to scrap. For example, if you want to get a link from a tag inside div tag the query will be like this.

$query = $liteGrabber->div([], true)->a()->atSrc()->getQuery();

OR Since 1.2 you can build the query simpler than before. The way it works is like this.

$query = $liteGrabber->div()->a()->atSrc()->getQuery();

Third, let's get the result!

$liteGrabber->getResult();

The result will be returned in a form of array. The result will be an empty array if your query compositions don't match with the actual element on a web page you want to scrap.

Query Explanation

On the second step above, you see that div([], true) have to parameters. The first one is specification of tag attribute. If you want to scrap specifically from div which has certain class attribute with certain value. You have to set the array.

div(['class' => 'post-wrapper home'], true)

Example above will set the query to <div class="post-wrapper home">. You MUST NOT forget to put second argument to true for the first query. Whoops don't worry since version 1.2 you MAY forget to put arguments for the first query. The default is set to empty array for first argument and true for second argument.

If you have done arranging the query, end it with getQuery() to make sure that you reach the end of query and ready to process to the next step.

The LiteGrabber is tested with PHPUnit.

统计信息

  • 总下载量: 84
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固