使用Python抓取google街景照片

Google map 提供Google Street View Image API让我们使用。

在:https://developers.google.com/maps/documentation/streetview/



下图是一些街景照片的参数信息。

size:图片尺寸

location:经纬度

heading:朝向角度

pitch:旋转角度

key:自己的API_KEY




下面的URL则是获得街景图片的URL,将上面参数拼在一起即可:

url = "https://maps.googleapis.com/maps/api/streetview?size=600x300&location=46.414382,10.013988&heading=151.78&pitch=-0.76&key="#你的KEY"



1. 首先要建一个项目,获取YOUR_API_KEY

2.按照url的格式进行构造

3.使用rullib2的方法下载并保存图片

# _*_ coding: utf-8 _*_
__author__ = 'Administrator'

import urllib2
import threading
from optparse import OptionParser
from bs4 import BeautifulSoup
import sys
import re
import urlparse
import Queue
import hashlib

def download(url, name):
	path = "C:\\Users\\Administrator\\Desktop\\GPS"
	#url = "http://pic2.sc.chinaz.com/files/pic/pic9/201309/apic520.jpg"
	#url = "https://maps.googleapis.com/maps/api/streetview?size=600x300&location=46.414382,10.013988&heading=151.78&pitch=-0.76&key="#你的KEY"

	#保存文件时候注意类型要匹配,如要保存的图片为jpg,则打开的文件的名称必须是jpg格式,否则会产生无效图片
	conn = urllib2.urlopen(url)
	f = open(name, 'wb')
	f.write(conn.read())
	f.close()
	print('Pic Saved!')
fp = open("C:\\Users\\Administrator\\Desktop\\GPS\\paris.txt", "r")

for line in fp.readlines():
	line =  (lambda x: x[11:-11])(line)
	zu = line.split('_')
	jin = zu[0]
	wei = zu[1]
	heading = zu[2]
	name = "C:\\Users\\Administrator\\Desktop\\GPS\\paris_sub\\" + jin + "_" + wei + "_" + heading + "_-004.JPG"
	url = "https://maps.googleapis.com/maps/api/streetview?size=936x537&location=" + jin + "," + wei + "&heading=" +heading + "&pitch=-004&key="#你的KEY"
	#print zu
	print name
	#print url
	download(url, name)

fp.close()


下面是待下载的数据格式:


'paris_sub/48.651717_2.493865_270_-004.JPG'
'paris_sub/48.756312_2.069988_90_-004.JPG'
'paris_sub/48.759815_2.502092_90_-004.JPG'
'paris_sub/48.911445_1.850626_270_-004.JPG'
'paris_sub/48.893319_2.262638_90_-004.JPG'
'paris_sub/48.815737_2.412183_270_-004.JPG'
'paris_sub/48.905476_2.527302_90_-004.JPG'
'paris_sub/48.912099_2.285934_270_-004.JPG'
'paris_sub/48.772068_2.033889_90_-004.JPG'
'paris_sub/48.648679_2.306182_90_-004.JPG'
'paris_sub/48.618283_2.925704_90_-004.JPG'
'paris_sub/48.926558_1.941170_270_-004.JPG'
'paris_sub/48.881077_2.705896_90_-004.JPG'
'paris_sub/48.966915_2.477976_90_-004.JPG'
'paris_sub/49.105046_2.245066_270_-004.JPG'
'paris_sub/48.703037_2.216347_270_-004.JPG'
'paris_sub/48.791862_2.420343_90_-004.JPG'
'paris_sub/48.681379_2.660818_90_-004.JPG'
'paris_sub/48.712748_2.377744_90_-004.JPG'
'paris_sub/48.806908_2.604621_270_-004.JPG'
'paris_sub/48.652523_1.862794_90_-004.JPG'
'paris_sub/48.488890_2.270909_90_-004.JPG'
'paris_sub/48.525296_1.950706_270_-004.JPG'


最后下载成功的图片文件截图:



你可能感兴趣的:(谷歌,street,view,python)