O'Reilly logo

Instant PHP Web Scraping by Jacob Ward

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a reusable scraping class (Advanced)

Given the recipes we have completed so far, we are in a position where we can take on most scraping tasks that we may come across by developing a solution specific to any problem we may encounter. While this is a perfectly suitable approach, and is necessary for very large projects; for the types of small projects we will usually find ourselves feeling that it is overly time-consuming, and will see us often repeating ourselves.

In this recipe we will introduce some basic Object oriented programming (OOP) techniques to build a scraping class, which can be easily expanded and reused for any projects we may embark on in the future.

How to do it...

  1. Enter the following code into a new PHP file:
    <?php class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required