如何从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:
- Open the Airbnb listing page, then hit
F12(orCtrl+Shift+Ion Windows/Linux,Cmd+Opt+Ion Mac) to launch your browser’s DevTools. - Option A: Search the DOM
- Go to the
Elementstab, pressCtrl+F(orCmd+F), and search forlatitudeorlongitude. You’ll often find these values tucked inside a JSON object in a<script>tag (look for tags withtype="application/json").
- Go to the
- Option B: Check Network Requests
- Switch to the
Networktab, refresh the page, and filter requests byXHR/Fetch. - Search for keywords like
pdp_listing_detailorgeolocation—the response from these requests will include a full JSON payload with the listing’s geographic data, includinglatandlngfields.
- Switch to the
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
相关产品推荐
相关产品推荐

