从地图提取数据(JsonObj)

时间:2019-03-13 11:26:04

标签: python json python-requests

我正在寻找所有法国地图的废纸。

我有一个问题:

1-我受地图缩放的限制

import requests




url ='https://www.iadfrance.fr/agent-search-location?southwestlat=47.0270782&southwestlng=-2.1560669&northeastlat=47.4930807&northeastlng=-1.0093689'
jsonObj = requests.get(url).json()
emails = jsonObj['agents']
#print (emails)


for agent in emails: 
    email = agent['email']
    print(email)

谢谢

2 个答案:

答案 0 :(得分:1)

我找到了正确的方法,我必须仔细考虑。 我已经在非常大的区域中手动设置了2个地理数据。 (一个在大西洋,另一个在俄罗斯)。 可行!

import requests


url ='https://www.iadfrance.fr/agent-search-location?southwestlat=9.884462&southwestlng=-35.58398&northeastlat=68.714264&northeastlng=44.796407'
jsonObj = requests.get(url).json()
emails = jsonObj['agents']
#print (emails)


for agent in emails: 
    email = agent['email']
    print(email)

答案 1 :(得分:1)

您必须在请求中使用经度,纬度参数来“缩小”

您可以手动更改它们,或者我是osmnx的粉丝。您可以使用它来获取不同区域的边界,然后以米为单位设置半径以创建边界框:

import requests
import osmnx as ox
import os

os.environ["PROJ_LIB"] = "C:/Users/xxxxxxx/AppData/Local/Continuum/anaconda3/Library/share"; #fixr

# Get a boundary box of a city/place/address
city = ox.gdf_from_place('Paris, France')

# Distance to make boundary from center in meters
# Essentially allows you to zoom out
distance = 300000

# Get centroid of that city/place boundary box
point = ( city['geometry'].centroid.x.iloc[0], city['geometry'].centroid.y.iloc[0] )

# Get a new boundary box a certain distance in North, South, East, West directions for x meters
boundary = ox.bbox_from_point(point, distance=distance , project_utm=False, return_crs=False)

sw_lat = boundary[3]
sw_lng = boundary[0]*-1
ne_lat = boundary[2]
ne_lng = boundary[1]*-1

# website to scrape https://www.iadfrance.fr/trouver-un-conseiller

url ='https://www.iadfrance.fr/agent-search-location'

# Here is the coordinates from orginial post
#payload = {
#'southwestlat': '47.0270782',
#'southwestlng': '-2.1560669',
#'northeastlat': '47.4930807',
#'northeastlng': '-1.0093689'}


payload = {
'southwestlat': sw_lat,
'southwestlng': sw_lng,
'northeastlat': ne_lat,
'northeastlng': ne_lng}


jsonObj = requests.get(url, params=payload).json()
emails = jsonObj['agents']
#print (emails)


for agent in emails: 
    email = agent['email']
    print(email)