【问题标题】:Extract data from a map (JsonObj)从地图中提取数据 (JsonObj)
【发布时间】:2019-08-04 01:34:33
【问题描述】:

我正在尝试抓取所有法国地图。

我有一个问题:

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)

谢谢

【问题讨论】:

  • 你的问题是什么?此代码运行良好
  • 是的,这段代码不是问题。如果您查看网站,我可以获取有限区域的电子邮件。这受地图 api 的 zoomOut 限制。我想从法国获取所有的代理,而不仅仅是一个部门。

标签: python json python-requests


【解决方案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)

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-26
      • 2021-09-26
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多