Scraping Review Data using ReviewAPI with PHP

Product Reviews are used in websites to give buyer an opportunity to rate and comment on product they have purchased. Right on the same page, other customers can read these reviews when making a purchase decision. Many websites, specially the eCommerce businesses looking for the reviews data from other websites to use for their business. But it’s not an easy task to get the reviews data from other websites as there are too many limitations to pass the process to scrape the reviews data.

If you’re trying to scrape reviews data manually then it will a very time consuming task. It involves adding several data sources, adaption to markup changes, managing proxy networks etc.

So if you’re running a business or a developer and looking for the solution to scrape the reviews data from different platform, then you’re here at right place. In this tutorial you will learn how to scrape the reviews data from different platform using ReviewAPI with PHP.

The ReviewAPI is an easy to use high speed reviews scrape API, developed by SaaS Industries. The API is developed in way to scrape structured and normalized review data from 30+ review platforms. The major available platforms are Amazon, Google, Yelp, Facebook, Tripadvisor and many more.

Also, read:


We will cover this tutorial in easy steps to integrate the ReviewAPI with PHP.

Step1: Get API Key

To access the ReviewAPI, we need to sign up on ReviewAPI to create an account to access the user dashboard where we will get the API Key.

We will use the API Key to make the HTTP request to the API.

https://app.reviewapi.io/api/v0/search?apikey=APIKEY

Step2: Create Data Query

We will create the data query to scrape the reviews data. We will use parameter url and pass the website URL to the reviews data.

<?php 

$dataQuery = [
	'url' => 'https://www.yelp.at/biz/teddy-s-red-tacos-los-angeles-2',
	'type' => '',
];

?>

Step3: Make HTTP Request to ReviewAPI

We will make HTTP request to ReviewAPI using PHP Curl function. We will API Key and data query with the request to scrape the reviews data. We will store the response data into $responseData variable.


<?php 

$apiKey = "YOUR_API_KEY";

$ch = curl_init();

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_URL, 'https://app.reviewapi.io/api/v0/reviews?' . http_build_query($dataQuery));

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	"Content-Type: application/json",
	"apikey: $apiKey",
));

$responseData = curl_exec($ch);
curl_close($ch);

?>

Step4: Decode Response Data

We will decode the response data into JSON using PHP json_decode() function and store the JSON data into $resultData variable.

<?php

$resultData = json_decode($responseData);

var_dump($resultData);

?>

Step5: Complete Code

Here is the complete example code to make HTTP request to ReviewAPI with the data query to scrape the reviews data and get data into JSON format.

<?php

$apiKey = "YOUR_API_KEY";

$ch = curl_init();

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);

$dataQuery = [
	'url' => 'https://www.yelp.at/biz/teddy-s-red-tacos-los-angeles-2',
	'type' => '',
];

curl_setopt($ch, CURLOPT_URL, 'https://app.reviewapi.io/api/v0/reviews?' . http_build_query($dataQuery));

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	"Content-Type: application/json",
	"apikey: $apiKey",
));

$responseData = curl_exec($ch);
curl_close($ch);

$resultData = json_decode($responseData);

var_dump($resultData);

?>

Below is the sample reviews scrape data in JSON format using ReviewAPI.

{
"source": "Google",
"reviewAge": "3w"
"rating": 2,
"maxRating": 5,
"reviewerName": "Mr. Miller",
"reviewText": "Came for the famous Sacher...",
}

Step6: Conclusion

Here in this tutorial we have explained how to consume ReviewAPI with PHP to scrape the reviews data. You can also use more advance options by going through the documentation in your ReviewAPI request.

You may also like:


Leave a Reply

Your email address will not be published. Required fields are marked *