gl vs hl vs location: Google Search API Locale Settings
Senior Web Scraping Engineer
TL;DR:
- gl, hl, and location describe different search inputs. Keep country, language, and search origin separate.
- Seven successful country requests demonstrate returned data. They do not establish a city-accuracy percentage.
- A useful localization test changes one variable at a time. Fix the query and other settings before comparing outputs.
- Requested settings belong beside observed evidence. Mark a location as unverified until an independent check supports it.
Introduction: A Country Code Is Only Part of a Search
Search results depend on more than a keyword. A country preference, language setting, and local origin each provide context, and they can produce different effects.
This guide explains gl versus hl versus location for Scrapeless Google Search API. It shows a seven-country request matrix and a method for checking local behavior independently. It does not treat a nonempty response as proof that a particular city was represented accurately.
The Google Search parameter contract is the reference for accepted controls. The actor request workflow stays the same as you change those controls inside input.
What Each Parameter Controls
The gl parameter selects the search country, hl selects the search language, and location specifies the requested search origin. These inputs should be stored separately in a collection record.
| Parameter | Example | What Not to Infer |
|---|---|---|
gl |
us |
Every result must belong to a US organization |
hl |
en |
Every destination page must be English |
location |
Austin, Texas, United States |
Every local result has been independently geocoded |
google_domain |
google.com |
A domain name alone establishes city accuracy |
Use the API's accepted values rather than automatically translating labels through an unrelated locale library. For example, the current reference uses uk for the United Kingdom. A general language or territory standard and a particular API's accepted values are not always identical.
The language-tag standard explains how language identification can include several subtags, but it does not expand the values accepted by hl. Likewise, Unicode locale conventions help describe locale data without replacing a service's parameter contract.
Keep Country Preference Separate From Language Restriction
The search-language input should not be interpreted as a guarantee that every result document uses that language. A language setting, a restriction on document language, and a query written in a particular language are distinct controls.
Google describes how language affects search results as involving more than one signal. In your experiment, record the query language as well as hl. A query written in English and one translated into Japanese are different experiments even if other inputs match.
Avoid translating the query while also changing country and city in the same comparison. If the results differ, you would not know which deliberate input change contributed to the difference. First isolate a single variable; then test the complete configuration that your application needs.
A Seven-Country Availability Example
Seven requests for coffee, all using hl=en, returned nonempty organic arrays when gl was changed across the following countries. Each completed with HTTP 200.
| Country | gl | hl | Returned Organic Records |
|---|---|---|---|
| United States | us | en | 8 |
| United Kingdom | uk | en | 9 |
| Germany | de | en | 9 |
| France | fr | en | 10 |
| Japan | jp | en | 10 |
| Canada | ca | en | 9 |
| Australia | au | en | 9 |
These counts demonstrate that data was returned for those configured requests. They do not measure country accuracy, language accuracy, or city accuracy. The requests did not include a city in location, and the returned destinations were not assigned independent geographic ground truth.
The different counts also do not prove that geography caused the differences. Each call is a separate search snapshot. A controlled study needs repeated observations and a predefined measurement before it can make a causal or accuracy claim.
Start Scraping with Scrapeless
Power up your web scraping and automation workflow with Scrapeless!
Sign up today and get $5 in free credit — no credit card required.Claim your free credit now in the Scrapeless Dashboard.
Save a Reproducible Country Matrix
The following program keeps the exact input and full response for every country and explicitly labels location validation as incomplete. This avoids turning a successful network request into an unsupported accuracy score.
Prerequisites are Python, Requests, and SCRAPELESS_API_KEY in the environment. Install Requests with python -m pip install requests, save the program as country_matrix.py, and run python country_matrix.py. Each run creates a separate directory under country-runs.
The helper handles pending tasks through the documented result workflow. The loop is sequential so the example does not assume an account-specific concurrency limit.
python
import json
import os
import time
from pathlib import Path
from urllib.parse import quote
import requests
BASE = "https://api.scrapeless.com/api/v1/scraper"
def google_search(query):
headers = {"x-api-token": os.environ["SCRAPELESS_API_KEY"]}
response = requests.post(
BASE + "/request", headers=headers,
json={"actor": "scraper.google.search", "input": query},
timeout=(10, 60), allow_redirects=False,
)
task_id = None
for poll in range(11):
response.raise_for_status()
if response.status_code not in (200, 201):
raise RuntimeError(f"Unexpected HTTP status: {response.status_code}")
data = response.json()
if not isinstance(data, dict):
raise ValueError("Expected a JSON object")
if response.status_code == 200:
return data
if task_id is None:
task_id = data.get("taskId")
if not isinstance(task_id, str) or not task_id:
raise ValueError("Pending response has no taskId")
if poll == 10:
raise TimeoutError(f"Task still pending; retain taskId={task_id}")
time.sleep(2)
response = requests.get(
BASE + "/result/" + quote(task_id, safe=""),
headers=headers, timeout=(10, 30), allow_redirects=False,
)
def organic_rows(data):
rows = data.get("organic_results")
if not isinstance(rows, list):
raise ValueError("organic_results is missing or is not an array")
if not all(isinstance(row, dict) for row in rows):
raise ValueError("organic_results contains a non-object item")
return rows
if __name__ == "__main__":
from datetime import datetime, timezone
run_dir = Path("country-runs") / datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S%fZ")
run_dir.mkdir(parents=True)
summary = []
for country in ("us", "uk", "de", "fr", "jp", "ca", "au"):
query = {"q": "coffee", "gl": country, "hl": "en"}
data = google_search(query)
(run_dir / f"{country}.json").write_text(json.dumps({"input": query, "response": data}, ensure_ascii=False, indent=2), encoding="utf-8")
rows = organic_rows(data)
summary.append({"gl": country, "hl": "en", "rows": len(rows), "location_verified": False})
(run_dir / "summary.json").write_text(json.dumps(summary, indent=2), encoding="utf-8")
print(json.dumps(summary))
The code leaves location_verified false even when data is returned. That field is an application decision, not a field claimed to exist in the API response. Change it only after completing your defined independent validation.
Validate a City Independently
A city validation should compare requested origin with location evidence in the returned page and an independent baseline. Nonempty organic results alone do not establish that match.
Start with a public query that has local intent, such as coffee shops. Keep q, gl, hl, search mode, and other filters fixed. Run one request with a fully specified Austin location and another with a fully specified Seattle location. The API's endpoint guidance recommends city-level locations and treats location and uule as mutually exclusive.
The preparation requests for those two city names each returned nine organic records. That confirms data availability for the configured inputs. It does not establish that the visible search location or every result matched the intended city.
Before collecting a larger sample, define your validation sheet. Useful columns include requested city, visible location evidence, sample local-business addresses where available, independent baseline method, observation time, and reviewer outcome. Save the associated metadata.rawUrl when present so the page can be inspected.
Use a manual baseline with documented settings or an independent trusted measurement. A reviewer should inspect the evidence rather than infer location solely from a country-code domain. A national publisher can appear in a local search, and a local business can use a generic domain.
Mark outcomes as confirmed, conflicting, or insufficient evidence. Do not force uncertain observations into a pass category. To publish an accuracy percentage, define the denominator and adjudication rule before looking at the results.
Keep Ongoing Comparisons Comparable
A localization dataset needs stable inputs and visible collection context. Save requested settings even if the response includes its own metadata; the two records answer different questions.
Record the query exactly, the requested country and language, any location string, search mode, collection time, and response outcome. Keep country-only baselines distinct from city-specific experiments. Do not compare a desktop web-search result with a Local-mode result as though only the city changed.
For a production workflow, decide what should happen when location evidence is missing. Holding that observation for review is more informative than presenting it as a validated city snapshot. Use current pricing to budget repeated observations and independent checks separately.
Conclusion: Validate the Location You Claim
Country, language, and city inputs make search collection more deliberate, but the strongest location claim must match the evidence. Begin with a small configuration matrix, preserve the responses, and validate the intended geography before building city-level reporting.
The Google Search API product page introduces the service; the parameter contract controls implementation. Treat a successful response as the start of validation rather than the end of it.
Build Your Search Data Workflow
Join developers working with search data in our community: Discord · Telegram.
Create a Scrapeless account and apply this tutorial to a small query set before scheduling a larger collection.
FAQ
Q: Are gl and hl interchangeable?
No. gl selects the search country and hl selects the search language. Store and test them separately.
Q: Does hl=en restrict every result to English?
Do not treat it as a guarantee about every result document. Search-language settings and document-language restrictions are different concepts.
Q: Can location and uule be supplied together?
No. The current parameter contract makes them mutually exclusive. Choose the supported control that fits your configuration.
Q: Do seven nonempty country responses prove seven-country accuracy?
No. They show returned data for seven requested configurations. Accuracy needs independently checked location evidence.
Q: Is a country-code domain sufficient proof of local relevance?
No. Domain naming alone does not establish the page's geography or the origin represented by the SERP.
Q: Does the example require a browser or AI agent?
No. It uses Python and the HTTP API. Independent visual validation may involve a browser, but that is a separate verification step.
At Scrapeless, we only access publicly available data while strictly complying with applicable laws, regulations, and website privacy policies. The content in this blog is for demonstration purposes only and does not involve any illegal or infringing activities. We make no guarantees and disclaim all liability for the use of information from this blog or third-party links. Before engaging in any scraping activities, consult your legal advisor and review the target website's terms of service or obtain the necessary permissions.



