从地图中提取数据(JsonObj)

问题描述 投票:0回答:2

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

我有一个问题:

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)

谢谢

python json python-requests
2个回答
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
投票

你必须利用请求中的经度,纬度参数来“缩小”

你可以手动更改它们,或者我是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)
© www.soinside.com 2019 - 2024. All rights reserved.