【发布时间】:2018-03-20 14:24:18
【问题描述】:
我正在尝试使用一些代码来下载 Google 街景图像。
到目前为止的代码是:
import urllib, os
import urllib.request
myloc = r"C:\Users\blah\blah" #replace with your own location
key = "&key=" + "enter your key" #got banned after ~100 requests with no key
def GetStreet(Add,SaveLoc):
base = "https://maps.googleapis.com/maps/api/streetview?size=400x400&location="
MyUrl = base + Add + key
fi = Add + ".jpg"
urllib.request.urlretrieve(MyUrl, os.path.join(SaveLoc,fi))
Tests = ["457 West Robinwood Street, Detroit, Michigan 48203",
"1520 West Philadelphia, Detroit, Michigan 48206",
"2292 Grand, Detroit, Michigan 48238",
"15414 Wabash Street, Detroit, Michigan 48238",
"15867 Log Cabin, Detroit, Michigan 48238",
"3317 Cody Street, Detroit, Michigan 48212",
"14214 Arlington Street, Detroit, Michigan 48212"]
for i in Tests:
GetStreet(Add=i,SaveLoc=myloc)
我通过导入urllib.request 并添加urllib.request.urlretrieve(MyUrl, os.path.join(SaveLoc,fi)) 来克服AttributeError: module ‘urllib’ has no attribute ‘urlretrieve’ 来添加它。
但是现在我收到了urllib.error.HTTPError: HTTP Error 400: Bad Request,但我不太清楚为什么或如何解决这个问题。
【问题讨论】:
标签: python python-3.x google-maps urllib google-street-view