With the environment set up, you are ready to begin scraping Google Shopping Product Specs using our API. This is a straightforward process and apart from what was discussed above, all you need to do is to get the product ID of the product you are interested in.
Tip: This is how you can get the product ID of a product from Google Shopping:
Having now set up Node.js , an API key and a product ID ,you are now ready to start scraping. In order to get started now, create a js file, or use the one you created for the above section and import Node.js built in `https` module which enables you to send requests to our API. This can be done as follows:
const https = require("https");
Secondly, you need to specify your API key and the product_id property of the product you are interested:
const API_KEY = "YOUR-API-KEY-HERE" // You can obtain one by registering here
const PRODUCT_ID = "11607214845071611155"
Next, you need to pass this information in an options object in order to let our API know what is product you are looking to scrape:
const options = {
"method": "GET",
"hostname": "serpapi.webscrapingapi.com",
"port": null,
"path": `/v1?engine=google_product&api_key=${API_KEY}&product_id=${PRODUCT_ID}`,
"headers": {}
};
And lastly, you need to set up a call to our API with all this information:
const req = http.request(options, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
const results = JSON.parse(body.toString());
const product_specs = results.specs_results;
console.log(product_specs)
});
});
req.end();
All that is left for you to do now is to execute the script you have created and wait for the results:
$ node scraper.js
And you should now receive your results:
{
display: {
native_aspect_ratio: '16:9',
screen_shape: 'Flat',
led_backlighting_type: 'Direct-LED',
display_technology: 'LCD',
display_resolution: '1920 x 1080 pixels'
}
}
And that's it! You have successfully scraped Google Shopping product specifications using our API, and you can now utilize the obtained data for various purposes such as price comparison, market research, SEO optimization, and more. For further reference and code samples in the other six programming languages, you can check out our Google Product API documentation.