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

如何爬取Google Streetview延时视图?实现年份获取与图片抓取

爬取Google街景延时视图年份与滑块切换解决方案

最优方案:绕过前端滑块,直接调用API

Google街景延时视图的历史数据本质是通过后端API返回的,与其费力模拟JS滑块交互,不如直接获取所有可用年份的全景ID(panoid),再请求对应图片,效率和稳定性都更高。

步骤1:提取基础全景ID

从你提供的URL中可以直接提取当前全景的panoid:c1y9nJwHAUOEIJnwtnmpLQ,这是获取历史数据的起点。

步骤2:获取该地点的所有历史全景数据

发送GET请求到Google街景元数据API,传入当前panoid,返回的JSON会包含所有可用年份的全景条目,每个条目都有对应的panoid、拍摄年份等信息。

Python实现示例:

import requests

panoid = "c1y9nJwHAUOEIJnwtnmpLQ"
# 替换为你自己的Google Maps API密钥
url = f"https://maps.googleapis.com/maps/api/streetview/metadata?pano={panoid}&key=YOUR_API_KEY"
response = requests.get(url)
history_data = response.json()

返回结果的links字段会列出所有历史全景的关联信息,从中可提取每个年份对应的panoid。

步骤3:生成对应年份的街景图片URL

拿到目标年份的panoid后,直接构造图片请求URL,无需操作前端滑块:

def generate_streetview_img_url(panoid, width=16384, height=8192, yaw=214.07529, pitch=0):
    return f"https://streetviewpixels-pa.googleapis.com/v1/thumbnail?panoid={panoid}&w={width}&h={height}&yaw={yaw}&pitch={pitch}&thumbfov=100"

# 遍历历史全景数据,下载对应图片
for entry in history_data.get("links", []):
    year_panoid = entry["pano"]
    img_url = generate_streetview_img_url(year_panoid)
    img_response = requests.get(img_url)
    # 按年份保存图片
    with open(f"streetview_{entry['description']}.jpg", "wb") as f:
        f.write(img_response.content)

备选方案:模拟滑块点击(不推荐)

如果坚持要通过前端交互实现,可使用Selenium工具定位JS触发元素,模拟点击操作:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()
driver.get("你的目标街景URL")

# 打开延时视图弹窗(定位时间轴按钮)
timeline_btn = driver.find_element(By.CSS_SELECTOR, "div[aria-label='查看历史影像']")
timeline_btn.click()
time.sleep(2)

# 定位滑块轨道,模拟点击切换年份
slider_track = driver.find_element(By.CSS_SELECTOR, "div.gm-style-cc > div:nth-child(2) div[role='slider']")
actions = ActionChains(driver)
actions.move_to_element(slider_track).click().perform()
time.sleep(1)

# 提取当前页面的panoid,生成图片URL
current_panoid = driver.current_url.split("!1s")[1].split("!")[0]

注意:该方式容易因Google页面结构更新失效,且可能触发反爬机制,仅作为备选。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 21:20:44