Baidu map provides open API and usage
Login account in the upper right corner - > click "get key" - > "create application" - > fill in the application name & white list IP - > then copy AK (for ex amp le, u2uqy7Gxui0XyBdcHLU0D3hQINLKokc0)
And go straight to the code
API provides three ways
1 search of administrative divisions
2 circular area search
3 rectangular area retrieval
Details can be seen. API details
This paper takes 1,3 as an example
import requests url = "http://api.map.baidu.com/place/v2/search" querystring = {"query":"market","region":"Shenzhen","output":"json","ak":"Your ak","page_size":20,"page_num":0} response = requests.request("GET", url, params=querystring) r = response.json() print(r['results']) print(len(r['results']))
The results are as follows
[{'name': 'Nanshan Market', 'location': {'lat': 22.531757, 'lng': 113.926754}, 'address': 'Nanxin Road 2008', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Nanshan District', 'street_id': 'd6df91c124f80073f7b9164d', 'telephone': '13590117093', 'detail': 1, 'uid': 'd6df91c124f80073f7b9164d'}, {'name': 'Sungang stationery toy wholesale market', 'location': {'lat': 22.564115, 'lng': 114.114963}, 'address': '1025 Baoan North Road', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Luohu District', 'street_id': '28e700f171893318095cb34a', 'telephone': '(0755)82268844', 'detail': 1, 'uid': '28e700f171893318095cb34a'}, {'name': 'Zhangbei comprehensive market', 'location': {'lat': 22.692344, 'lng': 114.255645}, 'address': 'No.216 Zhangbei Road, Longgang District, Shenzhen City, Guangdong Province', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longgang District', 'street_id': '4fc3161a8a8d3db03a13fd59', 'detail': 1, 'uid': '4fc3161a8a8d3db03a13fd59'}, {'name': 'Shenzhen US market', 'location': {'lat': 22.796433, 'lng': 113.951935}, 'address': 'Xiledo department store, Guangming New District, Guangming District, Shenzhen City, Guangdong Province(Kang Ming Road East)', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Guangming District', 'street_id': '5ffe414874a5986d9fec2b06', 'detail': 1, 'uid': '5ffe414874a5986d9fec2b06'}, {'name': 'Niuhu agricultural trade market', 'location': {'lat': 22.730088, 'lng': 114.095257}, 'address': 'Beside Golf Avenue, niuhu village, Guanlan town', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longhua District', 'street_id': '8f6d8c61968269a36c47605b', 'detail': 1, 'uid': '8f6d8c61968269a36c47605b'}, {'name': 'Pingshan comprehensive wholesale market', 'location': {'lat': 22.695807, 'lng': 114.346117}, 'address': 'Liuhe construction site beside bus station of Pingshan wholesale market, No. 470, Dongzong Road, Pingshan District', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Pingshan District', 'street_id': '550fd5f96c6d9060931fc955', 'detail': 1, 'uid': '550fd5f96c6d9060931fc955'}, {'name': 'Ping West Market', 'location': {'lat': 22.765712, 'lng': 114.292258}, 'address': '23 Jixiang 1st Road', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longgang District', 'street_id': '87248d96c13e62aa2806ce5a', 'detail': 1, 'uid': '87248d96c13e62aa2806ce5a'}, {'name': 'Youxin frozen food city', 'location': {'lat': 22.66691, 'lng': 114.13473}, 'address': '78 Pingji Avenue, shanglilang community, Nanwan street, Longgang District, Shenzhen', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longgang District', 'street_id': 'd8ef3b08c51b727a58bbbc69', 'telephone': '(0755)88263688', 'detail': 1, 'uid': 'd8ef3b08c51b727a58bbbc69'}, {'name': 'Shiyan new village comprehensive market', 'location': {'lat': 22.679288, 'lng': 113.930496}, 'address': '301, No. 1, Wangjiazhuang market, Bao'an District, Shenzhen', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Baoan District', 'street_id': '593850fb068b9720df1e526b', 'detail': 1, 'uid': '593850fb068b9720df1e526b'}, {'name': 'Xinpitou agricultural trade market', 'location': {'lat': 22.807519, 'lng': 113.948556}, 'address': '13 Kanghong Road, Guangming District, Shenzhen', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Guangming District', 'detail': 1, 'uid': '3a0a78bd2b341d86631809d9'}, {'name': 'Aihua meat and vegetable market', 'location': {'lat': 22.544775, 'lng': 114.098053}, 'address': '47 Aihua Road', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Futian District', 'street_id': 'b533ea4af6bb89584f6d4645', 'telephone': '(0755)83620019', 'detail': 1, 'uid': 'b533ea4af6bb89584f6d4645'}, {'name': 'Xikeng old village comprehensive market', 'location': {'lat': 22.69478, 'lng': 114.036412}, 'address': 'New District Guanlan', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longhua District', 'street_id': '50fb64ff5a658e20e9f8531b', 'telephone': '13885524446', 'detail': 1, 'uid': '50fb64ff5a658e20e9f8531b'}, {'name': 'Limin agricultural trade wholesale market', 'location': {'lat': 22.742953, 'lng': 114.289898}, 'address': 'No. 1256, Shenhui Road, Longgang District, Shenzhen City, Guangdong Province', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longgang District', 'street_id': '61f634f6fce2e8616a49f3aa', 'detail': 1, 'uid': '61f634f6fce2e8616a49f3aa'}, {'name': 'Longgang first market', 'location': {'lat': 22.73833, 'lng': 114.287002}, 'address': 'Longgang first market, Longgang District, Shenzhen City, Guangdong Province(Longgang Avenue West)', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longgang District', 'street_id': '0143dd2b837c3381cf06a435', 'detail': 1, 'uid': '0143dd2b837c3381cf06a435'}, {'name': 'HuiLongPu comprehensive market', 'location': {'lat': 22.736316, 'lng': 114.241372}, 'address': '26 Longping West Road, Longgang District, Shenzhen', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longgang District', 'street_id': 'd219bb1dc2beb792f50e775d', 'telephone': '18926789088', 'detail': 1, 'uid': 'd219bb1dc2beb792f50e775d'}, {'name': 'Gongming comprehensive market', 'location': {'lat': 22.786351, 'lng': 113.899172}, 'address': '145 Zhenming Road, Gongming street, Guangming District-5', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Guangming District', 'detail': 1, 'uid': '1eeed5464e94e5ebb5147f4c'}, {'name': 'Minzhi comprehensive market', 'location': {'lat': 22.630651, 'lng': 114.045652}, 'address': '412 Minzhi Avenue, Longhua District, Shenzhen', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longhua District', 'street_id': 'd0b8923fcf5d4bfbb5f42f5f', 'detail': 1, 'uid': 'd0b8923fcf5d4bfbb5f42f5f'}, {'name': 'Liyuan wholesale market', 'location': {'lat': 22.698857, 'lng': 114.141112}, 'address': '7 jingxiusan lane, Pinghu Town', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longgang District', 'street_id': '7ee3ccf7b8aed470047ce87c', 'telephone': '(0755)28852881', 'detail': 1, 'uid': '7ee3ccf7b8aed470047ce87c'}, {'name': 'Fumin railway market', 'location': {'lat': 22.617064, 'lng': 114.126306}, 'address': '164 Buli Road, Longgang District, Shenzhen City, Guangdong Province', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Longgang District', 'street_id': '96e3e1a27685cb82cae33c57', 'detail': 1, 'uid': '96e3e1a27685cb82cae33c57'}, {'name': 'Yantian seafood wholesale market', 'location': {'lat': 22.590926, 'lng': 114.284179}, 'address': '28 seafood street, Yantian District, Shenzhen', 'province': 'Guangdong Province', 'city': 'Shenzhen City', 'area': 'Yantian District', 'street_id': 'fc7675243816e6e34f776ea2', 'telephone': '(0755)25202868', 'detail': 1, 'uid': 'fc7675243816e6e34f776ea2'}]
Return to 20
The maximum page size is 20
The page number can be controlled by the page num parameter
Here's the point!
But it's Baidu's limit to return up to 400 through the location search of the administrative region
In this case, you need to search through the rectangular area
Shenzhen is divided into several regions for retrieval
The coordinates of a and b are located here Coordinate pick site
import requests import time import json keyword = "Food market" city = "Shenzhen" url = "http://api.map.baidu.com/place/v2/search" a = "22.4717881915,113.7808575851" b = "22.7960248910,114.3961567319" #a is the coordinates of the lower left corner of Shenzhen, b is the coordinates of the upper right corner of Shenzhen left_bottom = [113.7808575851,22.4717881915] # Set the coordinates of the lower left corner of the area (Baidu coordinate system) right_top = [114.3961567319,22.7960248910] # Set the coordinates of the upper right corner of the area (Baidu coordinate system) part_n = 5 # Set area grid (5 * 5) x_item = (right_top[0]-left_bottom[0])/part_n y_item = (right_top[1]-left_bottom[1])/part_n n = 0 # Slice counter url0 = 'http://api.map.baidu.com/place/v2/search?' data = [] for i in range(part_n): for j in range(part_n): left_bottom_part = [left_bottom[0]+i*x_item,left_bottom[1]+j*y_item]; # Bottom left corner coordinate of slice right_top_part = [right_top[0]+i*x_item,right_top[1]+j*y_item]; # Top right coordinate of slice for k in range(20): time.sleep(0.6) url = url0 + 'query=' + 'market' + '&page_size=20&page_num=' + str(k) + '&scope=1&bounds=' + str( left_bottom_part[1]) + ',' + str(left_bottom_part[0]) + ',' + str(right_top_part[1]) + ',' + str( right_top_part[0]) + '&output=json&ak=' + 'Your ak' print(str(left_bottom_part[1]) + ',' + str(left_bottom_part[0])) print(str(right_top_part[1]) + ',' + str(right_top_part[0])) print('===================================================') response = requests.request("GET", url) response = response.json() print(response) r = response['results'] data.append(r)
In this way, we can break the limit of Shenzhen region 400, which can be divided into 1010, more detailed 1010, and return 1200 + results