2017 © Pedro Peláez
 

library litegrabber

Grab content from a website using DOMXPath class in PHP

image

aprillins/litegrabber

Grab content from a website using DOMXPath class in PHP

  • Wednesday, April 29, 2015
  • by aprillins
  • Repository
  • 1 Watchers
  • 0 Stars
  • 36 Installations
  • HTML
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 3 % Grown

The README.md

LiteGrabber

LiteGrabber is a simple website content scrapper that utilizing the default PHP DOMXPath class., (*1)

Installation

You can install LiteGrabber using Composer., (*2)

composer require aprillins/litegrabber:dev-master, (*3)

Then, update your package., (*4)

composer update, (*5)

Don't forget to execute composer dumpautoload after the installation., (*6)

Usage

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

$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., (*8)

$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., (*9)

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

Third, let's get the result!, (*10)

$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., (*11)

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., (*12)

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., (*13)

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., (*14)

The LiteGrabber is tested with PHPUnit., (*15)

The Versions

29/04 2015

dev-master

9999999-dev

Grab content from a website using DOMXPath class in PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar aprillins

29/04 2015

1.2

1.2.0.0

Grab content from a website using DOMXPath class in PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar aprillins

18/04 2015

1.1

1.1.0.0

Grab content from a website using DOMXPath class in PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar aprillins

18/04 2015

1.0

1.0.0.0

Grab content from a website using DOMXPath class in PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar aprillins