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

如何从Airbnb房源嵌入的Google Map抓取经纬度数据

How to Extract Latitude and Longitude from Airbnb's Embedded Google Map

Hey there! I’ve dealt with this exact problem before, so let me share a few practical ways to pull the latitude and longitude data from an Airbnb listing’s embedded map—using your example link https://www.airbnb.jp/rooms/11171169 as a reference.

Method 1: Use Browser Developer Tools (Manual Approach)

This is the quickest way if you just need coords for a single listing:

  1. Open the Airbnb listing page, then hit F12 (or Ctrl+Shift+I on Windows/Linux, Cmd+Opt+I on Mac) to launch your browser’s DevTools.
  2. Option A: Search the DOM
    • Go to the Elements tab, press Ctrl+F (or Cmd+F), and search for latitude or longitude. You’ll often find these values tucked inside a JSON object in a <script> tag (look for tags with type="application/json").
  3. Option B: Check Network Requests
    • Switch to the Network tab, refresh the page, and filter requests by XHR/Fetch.
    • Search for keywords like pdp_listing_detail or geolocation—the response from these requests will include a full JSON payload with the listing’s geographic data, including lat and lng fields.

Method 2: Extract via Browser Console (Quick Script)

If you prefer a faster manual method, run this snippet in the DevTools Console tab:

// Look for the global state object (Airbnb uses different state managers sometimes)
const state = window.__INITIAL_STATE__ || window.__APOLLO_STATE__;
if (state?.listing) {
  console.log(`Latitude: ${state.listing.lat}`);
  console.log(`Longitude: ${state.listing.lng}`);
} else {
  // Fallback: Search for map-related data in the page
  const mapScripts = document.querySelectorAll('script');
  mapScripts.forEach(script => {
    if (script.textContent.includes('lat') && script.textContent.includes('lng')) {
      const match = script.textContent.match(/"lat":([\d.-]+),"lng":([\d.-]+)/);
      if (match) console.log(`Lat: ${match[1]}, Lng: ${match[2]}`);
    }
  });
}

Method 3: Automated Scraping (Python Example)

If you need to pull coords for multiple listings, here’s a Python script using requests and BeautifulSoup (note: always comply with Airbnb’s Terms of Service and robots.txt):

import requests
import json
from bs4 import BeautifulSoup

# Target listing URL
url = "https://www.airbnb.jp/rooms/11171169"

# Mimic a real browser to avoid being blocked
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(url, headers=headers)
soup = BeautifulSoup(response.text, "html.parser")

# Scan all JSON script tags for listing data
for script in soup.find_all("script", type="application/json"):
    try:
        data = json.loads(script.string)
        # Check for common state objects that hold listing data
        if "__INITIAL_STATE__" in data and "listing" in data["__INITIAL_STATE__"]:
            listing = data["__INITIAL_STATE__"]["listing"]
            lat, lng = listing.get("lat"), listing.get("lng")
            print(f"Extracted Coords: Latitude = {lat}, Longitude = {lng}")
            break
    except json.JSONDecodeError:
        continue

Important Notes

  • Airbnb’s page structure changes occasionally, so if one method stops working, try another (the network request method is usually the most reliable).
  • Always respect Airbnb’s scraping policies—avoid aggressive crawling that could overload their servers.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:57:41