Http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding
http://lbs.amap.com/api/webservice/guide/api/georegeo/#geo
Look at the document and then parse it through Python.
defGet_jingwei (url,data=None):Try: Res=requests.get (URL) data=json.loads (res.text) Jingwei=data["geocodes"][0][" Location"] District=data["geocodes"][0]["District"] Data={ "Jingwei": Jingwei,"URL": URL,"District":d Istrict}#Sheet_bj_xq_jw.insert (data) exceptException as E:Print(E,count)finally: Sheet_bj_xq_jw.insert (data)defData2file (s): Path= R"C:\Users\Oscar\Desktop\data1.txt"file= Open (Path,"a") File.write ("\ n") File.write (str (s)) File.close ()if __name__=='__main__': """Connect to MongoDB"""Client= Pymongo. Mongoclient ("localhost", 27017) DB_BJ_XQ_JW= client["DB_BJ_XQ_JW"] SHEET_BJ_XQ_JW= db_bj_xq_jw["Sheet1"] Import Time fromxiaoqu_list_1020ImportList Count=0 Api_url= ["http://restapi.amap.com/v3/geocode/geo?address={}&output=json&key= your key&city=%e5%8c%97%e4%ba%. AC". Format (i) forIinchlist.split ()] forSingle_urlinchApi_url:#print (Single_url)Time.sleep (Math.radians (3)) Get_jingwei (Single_url) Count=count+1Print(count)
Python obtains latitude and longitude data via Baidu/geocoding API