A comprehensive guide to handling geolocation (gl) and language (hl) parameters correctly using the modern serpapi library.
If you have ever tried to scrape Google Shopping results for a specific country—say, looking for coffee machine prices in Jakarta, Indonesia—you might have encountered a frustrating problem.
Even though your script runs perfectly, the results often come back in USD, showing products from Walmart or Target instead of local marketplaces like Tokopedia or Shopee.
By default, Google serves results based on the IP address of the requester. If your server (or your proxy's exit node) is located in the US, Google will show you American results.
Many developers assume the location parameter is enough. It's not.
A common mistake developers make is relying solely on the location string.
While the location parameter is important, it is not always enough to force Google to switch the currency and language context entirely. You might get Jakarta location data, but still see prices in English or mixed currencies.
To get accurate data, you need to be explicit. You must tell the API exactly where you are and what language you speak.
location: The physical location (e.g., "Jakarta, Indonesia")gl: The Country Code (e.g., id for Indonesia) - dictates the region for search interesthl: The Language Code (e.g., id for Bahasa Indonesia) - ensures the UI text and currency formatting align with the local userHere is a robust script that fetches prices specifically for the Indonesian market:
Expected Output:
google_shopping instead of google?You might notice I set the engine parameter to "google_shopping".
The Google Shopping API returns clean, structured JSON specifically designed for product data.
| Feature | google engine |
google_shopping engine |
|---|---|---|
| Data Structure | Mixed HTML parsing | Clean JSON |
| Price Formatting | Inconsistent | Structured |
| Seller Info | Limited | Detailed |
| Condition (New/Used) | Not available | Available |
| Future-proof | Breaks on HTML changes | Stable API |
If you use the standard "google" engine, you get the main search page. While this page contains shopping ads, parsing them is harder.
| Country | gl Code |
hl Code |
Currency |
|---|---|---|---|
| Indonesia | id |
id |
IDR (Rp) |
| Singapore | sg |
en |
SGD ($) |
| Malaysia | my |
ms |
MYR (RM) |
| Thailand | th |
th |
THB (฿) |
| United States | us |
en |
USD ($) |
| United Kingdom | uk |
en |
GBP (£) |
Find the complete list of country and language codes in the SerpApi documentation.
Want to compare prices across multiple countries? Here's a pattern:
Output:
gl AND hlScraping is all about precision. By combining the correct gl and hl parameters with the google_shopping engine, you ensure that your application receives data that is actually relevant to your users' location.
location, gl, and hlgoogle_shopping engine for structured product dataI built a complete handbook for handling Pagination, Error Handling, and Localization issues using modern Node.js practices.
Check out my full portfolio:
Author: Roki Miftah Kamaludin
Role: Aspiring Customer Success Engineer
LinkedIn: linkedin.com/in/rokimiftah