Suddenly found that the Baidu API more and more useful, simple use of Baidu API precision positioning IP address. Python code included
Category:Python
(4778) (5)
November 27, 2016 08:13:13
API Service Address:
Http://lbsyun.baidu.com/index.php?title=webapi/high-acc-ip
How to use:
The first step, the application of the key (AK), as the basis for accessing the service;
The second step, the spelling sends the URL of the HTTP/HTTPS request, note the AK that needs to use the first step of the application;
The third step is to receive the data returned by the HTTP/HTTPS request (JSON/JSONP format)
Service Address:
Http://api.map.baidu.com/highacciploc/v1
Https://api.map.baidu.com/highacciploc/v1
Note: When applying for developer certification, the use of 163 mailbox authentication failed, do not know why (November 27, 2016 08:23:32)
Test Address:
http://api.map.baidu.com/highacciploc/v1?qcip=139.214.254.47&qterm=pc&ak= Naw5vg6u5teluz2stdslqpsyirkoiofz&coord=bd09ll&extensions=3
Feedback results:
{"Content": {"location": {"lat": 43.862307, "LNG": 125.332422}, "Locid": "fb823867162b178b3e180993e4638d41", "radius" : 2060684, "confidence": 0.2, "address_component": {"Country": "China", "province": "Jilin Province", "City": "Changchun", "District": "Nanguan District", " Street ":" People's Main Street "," Street_number ":" No. No. 5766 "," Admin_area_code ": 220102}," formatted_address ":" No. 5766 Renmin Street, Changchun Nanguan District, Jilin Province "," Business ":" Renmin Street, Nanling, Nanhu Park "}," result ": {" error ": 161," Loc_time ":" 2016-11-27 08:36:41 "}}
[Python]View PlainCopy
- #-*-Coding:utf-8-*-
- Import requests
- Import JSON
- s = requests.session ()
- url = ' http://api.map.baidu.com/highacciploc/v1?qcip=139.214.254.47&qterm=pc&ak=YourKey&coord= Bd09ll&extensions=3 '
- Header = {' user-agent ':' mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) gecko/20100101 firefox/50.0 '}
- Response = S.get (URL, headers = header, timeout = )
- Print (Response.text)
- JSON = Json.loads (response.text)
- Print (' Location: ' +str (json[' content ' [' formatted_address ']))
- Print (' Business Circle: ' +str (json[' content ' [' Business ']))
- Print (' Longitude: ' +str (json[' content ' [' location '] [' lat ']))
- Print (' Dimension: ' +str (json[' content ' [' location '] [' LNG '] )
- Print (' accuracy: ' +str (json[' content ' [' confidence ']))
- #练习时间: November 27, 2016 10:54:36
- #1, note the use of character encoding.
- #2, note Modify the user-agent in the requests request header.
- The data returned by #3, JSON may be int or float, etc., and note character conversions when printing.
- #4, replace the API with the IP address you need to query and your key string.
=====================
Input results
{"Content": {"location": {"lat": 43.862307, "LNG": 125.332422}, "Locid": "180d8c65fa25fefaf6eb9ae6481e1f4c", "radius" : 2060684, "confidence": 0.2, "address_component": {"Country": "China", "province": "Jilin Province", "City": "Changchun", "District": "Nanguan District", " Street ":" People's Main Street "," Street_number ":" No. No. 5766 "," Admin_area_code ": 220102}," formatted_address ":" No. 5766 Renmin Street, Changchun Nanguan District, Jilin Province "," Business ":" Renmin Street, Nanling, Nanhu Park "}," result ": {" error ": 161," Loc_time ":" 2016-11-27 10:45:03 "}}
Location: No. No. 5766, Renmin Street, Nanguan District, Changchun, Jilin Province
Shopping district: Renmin Street, Nanling, Nanhu Park
Longitude: 43.862307
Dimension: 125.332422
Accuracy: 0.2
API Precise Location IP address