QUICK TIP - Crawling Web Pages with PHPCrawl So Easy

0 1,269
Crawl Web | A&H Business Technology
Related posts

Uwe Hunfeld provides an object oriented library called PHPCrawl available at http://phpcrawl.cuab.de. This class can be used to crawl web pages with many different parameters. It also allows you to process each page and do what manipulation or scraping you need to do.

What is PHPCrawl?

PHPCrawl is a framework for crawling/spidering websites written in the programming language PHP, so just call it a webcrawler-library or crawler-engine for PHP

PHPCrawl “spiders” websites and passes information about all found documents (pages, links, files ans so on) for futher processing to users of the library.

It is high configurable and provides several options to specify the behaviour of the crawler like URL- and Content-Type-filters, cookie-handling, robots.txt-handling, limiting options, multiprocessing and much more.

PHPCrawl is completly free opensource software and is licensed under the GNU GENERAL PUBLIC LICENSE v2.

To get a first impression on how to use the crawler you may want to take a look at the quickstart guide or an example inside the manual section.
A complete reference and documentation of all available options and methods of the framework can be found in the classreferences-section

The current version of the phpcrawl-package and older releases can be downloaded from a sourceforge-mirror.


At least the following requirements are necessary to run phpcrawl (v 0.8) in basic single-process-mode:

  • PHP 5.2.1 or later version
  • PHP with OpenSSL-support for SSL-connections (https).
    Not necessary for http-connects.

In order to run phpcrawl in multi-process-mode, some additional requirements are needed:

  • The multi-process mode only works on unix-based systems (linux)
  • Scripts using the crawler in multi-process-mode have to be run from the commandline (PHP cli)
  • The PCNTL-extension for php (process control) has to be installed and activated.
  • The SEMAPHORE-extension for php has to be installed and activated.
  • The POSIX-extension for php has to be installed and activated.
  • The PDO-extension together with the SQLite-driver (PDO_SQLITE) has to be installed and activated.

Installation & Quickstart

The following steps show how to use phpcrawl:

  1. Unpack the phpcrawl-package somewhere. That’s all you have to do for installation.
  2. Include the phpcrawl-mainclass to your script or project. Its located in the “libs”-path of the package.

There are no other includes needed.

  1. Extend the phpcrawler-class and override the handleDocumentInfo-method with your own code to process the information of every document the crawler finds on its way.


    For a list of all available information about a page or file within the handleDocumentInfo-method see the PHPCrawlerDocumentInfo-reference.

    Note to users of phpcrawl 0.7x or before: The old, overridable method “handlePageData()“, that receives the document-information as an array, still is present and gets called. PHPcrawl 0.8 is fully compatible with scripts written for earlier versions.

  2. Create an instance of that class in your script or project, define the behaviour of the crawler and start the crawling-process.

    For a list of all available setup-options/methods of the crawler take a look at the PHPCrawler-classreference.

How to implement an Example

You accomplish this by overriding the base class and implementing your own functionality in the handleDocumentInfo() and handleHeaderInfo() functions. Use the code below as an example of how to create your own web crawler.

TinyURL for this post: https://tinyurl.com/y5uztngb

Sorry, The Comment Form Is Temporarily Closed At This Time
You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More