从地图中提取数据(JsonObj)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从地图中提取数据(JsonObj)相关的知识,希望对你有一定的参考价值。

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

我有一个问题:

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个地理数据。 (一个在大西洋,另一个在俄罗斯)。有用 !

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)
另一答案

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

你可以手动更改它们,或者我是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)

以上是关于从地图中提取数据(JsonObj)的主要内容,如果未能解决你的问题,请参考以下文章

如何从片段外部清除/重置地图?

使用从循环内的代码片段中提取的函数避免代码冗余/计算开销

怎么提取json里的数据变成EXCEL?

无法在片段内查看接收短信

从 Terraform 地图变量中提取键/值

谷歌地图没有从数据库中提取我的标记