How to scrape using Guzzle, Simple HTML Dom and anyIP.io?

By
Khaled Bentoumi

Reviewed By

Updated
October 19, 2023
12 min read

In this quick tutorial, we will show you how to start to scrape any website using Guzzle (a PHP library) and using rotating proxies from anyIP.io.

Guzzle installation

The recommended way to install Guzzle is through Composer.

Bash
    composer require guzzlehttp/guzzle
  

How to use Guzzle

Following the documentation, opening a page using Guzzle is pretty simple:

PHP
    $client = new GuzzleHttpClient(); 
$res = $client->request('GET', 'https://www.example.com'); 
echo $res->getBody();
  

To use a proxy, you have to add a proxy parameter:

PHP
    $res = $client->request("POST", "https://www.example.com", [ 
  "proxy" => "https://username:[email protected]", 
]);
  

How to parse the page?

The content of the page is in $res->getBody(). After checking that you actually got the correct result (the status code is 200, the content header is text or similar, etc.), you can start to parse the page. They are many options for this:

As a quick introduction to the scraping world, we will use Simple HTML Dom. After installing it and initialize it, you can simply use any CSS selector to retrieve the content of your choice:

PHP
    $simpleHTMLDom = str_get_html($res->getBody()); 
$links = $simpleHTMLDom ->find('a');
  
Khaled Bentoumi

Khaled is a software engineer. He’s been involved in many startups of different sizes. Previously, he founded Data to Page, an AI Programmatic SEO startup. He now handles all the marketing at anyIP.

Get access to millions of residential and mobile IPs
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Article by
Khaled Bentoumi

Khaled is a software engineer. He’s been involved in many startups of different sizes. Previously, he founded Data to Page, an AI Programmatic SEO startup. He now handles all the marketing at anyIP.

Read more
No items found.
12 min read
How to Choose the Best Proxy Service

To choose the best proxy service, consider their proxy types, features, traffic limits, and IP pool size. Otherwise, you may end up paying a lot of money for an inadequate proxy. In this article, we will go through critical considerations to make when choosing a proxy service.

No items found.
12 min read
Benefits of Using a Proxy

Significant pros of proxies include access to millions of IPs, anonymity, and bypassing IP bans. One of the primary purposes of using a proxy is to hide your IP address while undergoing said activities.

12 min read
Mobile Proxies Vs. Residential Proxies

Mobile and residential proxies share similarities and differences —connection and rerouting methods and how difficult they are to block aren't the same.

Ready for Next-Level Proxy Solutions?

Get started now and experience the ultimate in proxy flexibility, speed, and security.

Unlock the Power of anyIP Today!