You might want to use the backend endpoint.
For example:
import pandas as pd
import requests
from urllib.parse import urlencode
search_query = "Berlin, Germany"
payload = {
"c1": search_query,
"action": "gpcm",
"cp": "",
}
headers = {
"content-type": "application/x-www-form-urlencoded",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36",
"referer": "https://www.latlong.net/convert-address-to-lat-long.html",
"x-requested-with": "XMLHttpRequest",
"cookie": "".join(
f"{k}={v}" for k, v
in requests.get("https://www.latlong.net").cookies.get_dict().items()
),
}
response = requests.post(
"https://www.latlong.net/_spm4.php",
data=urlencode(payload),
headers=headers,
).text
df = pd.DataFrame(
[[*search_query.split(", "), *response.split(",")]],
columns=["City", "Country", "Latitude", "Longitude"],
)
print(df)
Output:
City Country Latitude Longitude
0 Berlin Germany 52.520008 13.404954
PS. Don't overuse this, as they're going to throttle your requests. Or use a VPN to keep quering.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…