You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从指定网页HTML中获取精准经纬度?地址转坐标存偏差

获取目标页面经纬度的简便方法

方法1:抓取页面的API接口数据

该网站的地图数据通过异步接口加载,你可以用浏览器开发者工具(F12)的「网络」面板筛选XHR/fetch请求,找到包含房源ID 151897164的详情API接口。这类接口返回的JSON数据里,通常会直接包含精确的经纬度字段。

示例代码(Python):

import requests

# 替换为实际找到的API接口URL
api_url = "https://www.sreality.cz/api/cs/v2/estates/151897164"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
}
response = requests.get(api_url, headers=headers).json()
# 根据实际返回结构提取经纬度
lat = response["_embedded"]["location"]["lat"]
lon = response["_embedded"]["location"]["lon"]
print(lat, lon)

方法2:优化地址解析精度

你当前用的地址praha zizkov krasova过于模糊,仅街道名,导致Nominatim返回结果有偏差。可以先从页面抓取带门牌号的完整房源地址,再用地理编码工具查询:

import requests
from bs4 import BeautifulSoup
import urllib.parse

# 抓取页面完整地址
url = "https://www.sreality.cz/detail/prodej/byt/1+kk/praha-zizkov-krasova/151897164"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
}
page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.text, "html.parser")
# 根据页面实际结构调整选择器
full_address = soup.find("div", class_="location-text").get_text(strip=True)

# 用完整地址查询Nominatim
nominatim_url = f"https://nominatim.openstreetmap.org/search/{urllib.parse.quote(full_address)}?format=json"
geo_response = requests.get(nominatim_url, headers=headers).json()
if geo_response:
    print(geo_response[0]["lat"], geo_response[0]["lon"])

注意事项

  • 调用网站API时需遵守robots.txt规则,避免频繁请求导致被封禁。
  • 地理编码的精度完全依赖地址完整性,地址越详细结果越准确。

内容的提问来源于stack exchange,提问作者Reda S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 21:45:50