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

Submitting a form using cURL (Intermediate)

Many times while web scraping, the data which we require is located behind a form. Whether that be a login form to a members area, a search form, a file upload, or any other form submission, it is frequently implemented using a POST request. The process of submitting a form with a POST request can be easily automated using PHP and cURL.

There are a number of steps required to successfully submit a POST form, such as capturing and analyzing HTTP headers, submitting the form, and in case of a login form, using cookies to store session data.

How to do it...

  1. Enter the following code into a new PHP project:
    <?php // Function to submit form using cURL POST method function curlPost($postUrl, $postFields, $successString) ...

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