google maps - Xpath for getting latitude and longitude -
i confused on how latitude , longitude values under "location" @ this url using 2 separate xpath's.
i using extract these 2 values coordinates of given zip code. coords.csv file empty when run "scrapy crawl latlng -o coords.csv -t csv" xpath or method have yielding coords must not correct
here code:
use googlemaps api find location given zip , extract latitude(lat) & longitude(lng) 'latlng' spider
zipcode = raw_input('zipcode: ') latlngurl = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s' % (zipcode,) latitude = 35 longitude = -79 class coordinates(scrapy.item): latitude = scrapy.field() longitude = scrapy.field() class latlngspider(scrapy.spider): name = "latlng" allowed_domains = ["googleapis.com"] start_urls = ( latlngurl, ) def parse(self, response): latitude = response.xpath('/geocoderesponse/result/geometry/location/lng').extract() longitude = response.xpath('/geocoderesponse/result/geometry/location/lat').extract() element in range(0, 2, 1): coords = coordinates() coords["latitude"] = latitude.pop(0) coords["longitude"] = longitude.pop(0) yield coords
if meant post (http://maps.googleapis.com/maps/api/geocode/xml?address=27517) address instead of 1 linked, xpath be:
/geocoderesponse/result/geometry/location/lat
and
/geocoderesponse/result/geometry/location/lng
if want in json, it's different.