python:Google Street View url请求无法作为json()加载

2024-06-02 08:41:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python抓取谷歌街景图片。 例如:

'url=https://maps.googleapis.com/maps/api/streetview?location=48.15763817939112,11.533002555370581&size=512x512&key=

我运行以下代码:

^{pr2}$

但却出现了一个错误:

Traceback (most recent call last):

  File "<ipython-input-69-180c2a4b335d>", line 1, in <module>
    result.json()

  File "/home/kang/.local/lib/python3.4/site-packages/requests/models.py", line 826, in json
    return complexjson.loads(self.text, **kwargs)

  File "/home/kang/.local/lib/python3.4/site-packages/simplejson/__init__.py", line 516, in loads
    return _default_decoder.decode(s)

  File "/home/kang/.local/lib/python3.4/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)

  File "/home/kang/.local/lib/python3.4/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())

JSONDecodeError: Expecting value

此url的响应是:

enter image description here

怎么解决? 非常感谢你。在


Tags: inpyselfhomereturnlibpackageslocal
2条回答

返回给您的响应中没有JSON,这就是它给出错误的原因。在

这里有一个新的Street View Image MetadataAPI,它确实返回JSON。

它将允许您查询给定位置(按地址或LATNG)的街景全景的可用性。如果找到全景,响应将包括其全景ID。这些查询是免费的。

否则,街景图像API将始终返回图像。这就是为什么引入了上面的JSON元数据API。

相关问题 更多 >