Having the environment set up, you can now start scraping Google Shopping Nearby Sellers 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:
You are now prepared to begin scraping after setting up Node.js, obtaining an API key, and acquiring a product ID. To proceed, either create a new JavaScript file or utilize the one created earlier and import Node.js's built-in `https` module, which allows you to send requests to the API, by using the following code:
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 = "4887235756540435899"
Next, you need to pass this information in an options object in order to let our API know what is the 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 nearbySellers = results.sellers_results.online_sellers;
console.log(nearbySellers)
});
});
req.end();
All 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:
[
{
position: 1,
name: 'Gamestop',
link: 'https://www.google.com/url?q=https://www.gamestop.com/consoles-hardware/playstation-5/consoles/products/sony-playstation-5-digital-edition-console/225171.html%3Futm_source%3Dgoogle%26utm_medium%3Dfeeds%26utm_campaign%3Dunpaid_listings&sa=U&ved=0ahUKEwi27suDvtP8AhVkk2oFHXzfDeMQ2ykIZg&usg=AOvVaw3ZevYyiKByTyo_THSF1qUJ',
additional_details: '460.5 mi · In stock at EulessToday: 10:00 AM - 9:00 PM',
base_price: '$399.99',
additional_price: { shipping: 'See website' },
total_price: '$399.99',
trusted: true
},
{
position: 2,
name: 'Gamestop',
link: 'https://www.google.com/url?q=https://www.gamestop.com/consoles-hardware/playstation-5/consoles/products/sony-playstation-5-digital-edition-console/225171.html%3Futm_source%3Dgoogle%26utm_medium%3Dfeeds%26utm_campaign%3Dunpaid_listings&sa=U&ved=0ahUKEwi27suDvtP8AhVkk2oFHXzfDeMQ2ykIcw&usg=AOvVaw1QiXFtHB6-CApj-HDvbNxl',
additional_details: '462.6 mi · In stock at ArlingtonToday: 11:00 AM - 8:00 PM',
base_price: '',
trusted: false
},
{
position: 3,
name: 'Gamestop',
link: 'https://www.google.com/url?q=https://www.gamestop.com/consoles-hardware/playstation-5/consoles/products/sony-playstation-5-digital-edition-console/225171.html%3Futm_source%3Dgoogle%26utm_medium%3Dfeeds%26utm_campaign%3Dunpaid_listings&sa=U&ved=0ahUKEwi27suDvtP8AhVkk2oFHXzfDeMQ2ykIdg&usg=AOvVaw0CxoqlJzdEZ93B-6U-Jmuf',
additional_details: '557.6 mi · In stock at HoustonToday: 12:00 PM - 9:00 PM',
base_price: '',
trusted: false
},
{
position: 4,
name: 'Gamestop',
link: 'https://www.google.com/url?q=https://www.gamestop.com/consoles-hardware/playstation-5/consoles/products/sony-playstation-5-digital-edition-console/225171.html%3Futm_source%3Dgoogle%26utm_medium%3Dfeeds%26utm_campaign%3Dunpaid_listings&sa=U&ved=0ahUKEwi27suDvtP8AhVkk2oFHXzfDeMQ2ykIeQ&usg=AOvVaw2BAlgtL85g1mvOonMQK14U',
additional_details: '568.6 mi · In stock at PasadenaToday: 12:00 PM - 9:00 PM',
base_price: '',
trusted: false
},
{
position: 5,
name: 'Gamestop',
link: 'https://www.google.com/url?q=https://www.gamestop.com/consoles-hardware/playstation-5/consoles/products/sony-playstation-5-digital-edition-console/225171.html%3Futm_source%3Dgoogle%26utm_medium%3Dfeeds%26utm_campaign%3Dunpaid_listings&sa=U&ved=0ahUKEwi27suDvtP8AhVkk2oFHXzfDeMQ2ykIfA&usg=AOvVaw3mi7jMt3aMSJde0sQb9yjR',
additional_details: '591.2 mi · In stock at San AntonioToday: 12:00 PM - 9:00 PM',
base_price: '',
trusted: false
},
...
]
You have now successfully scraped Google Product Nearby Sellers using our API. You can use the obtained data for various purposes such as price comparison, market research, SEO optimization and more. For more information and code samples in other six programming languages, feel free to refer to our Google Product API documentation.