Exemple #1
0
def getShopGeo():
	for i in range(1,11):
		shopName_xpath = '//tr[' + str(i + 1) + ']/td[1]'
		shopAddress_xpath = '//tr[' + str(i + 1) + ']/td[2]'
		shopName = driver.find_element_by_css_selector('#listhtml').find_element_by_xpath(shopName_xpath).text.encode('utf-8')
		shopAddress = driver.find_element_by_css_selector('#listhtml').find_element_by_xpath(shopAddress_xpath).text

		shop_address_encode = shopAddress.encode('utf-8')
		full_address = '上海市' + shop_address_encode

		try:
			# shopGeo = baiduAddressGeo.getGeoForAddress(full_address)
			# use google geo api
			shopGeo = googleAddressGeo.getGeoForAddress(full_address)
		except Exception, e:
			print 'can not get geo for this address'
			pass
		lat = shopGeo[0]
		lng = shopGeo[1]

		csvFile = open('./kfc_official_geo_google.csv', 'a')
		try:
			writer = csv.writer(csvFile)
			writer.writerow((shopName, lat, lng))
			# global id += 1
		finally:
			csvFile.close()
Exemple #2
0
csvData = open('./kfc_address_headless.csv', 'rb')
shopAddrData = csv.reader(csvData)

proxies = {'http':'http://127.0.0.1:8087'}

geoData = open('./kfc_official_geo_google.csv', 'a')
try:
	shopGeoWriter = csv.writer(geoData)
	shopGeoWriter.writerow(('shopAddress', 'lat', 'lng'))
finally:
	geoData.close()

for row in shopAddrData:
	# print row[1].decode('utf-8')
	address = row[1].decode('utf-8').encode('utf-8')
	shopGeo = googleAddressGeo.getGeoForAddress(address)
	lat = shopGeo[0]
	lng = shopGeo[1]
	print lat
	print lng

	geoData = open('./kfc_official_geo_google.csv', 'a')
	try:
		shopGeoWriter = csv.writer(geoData)
		shopGeoWriter.writerow((address, lat, lng))
		# global id += 1
	finally:
		geoData.close()
	
csvData.close()