首页 > 解决方案 > 无法在与任何随机城市相关的有效负载中使用 lat,long 的值?

问题描述

我编写了一个脚本来从网页中获取不同属性的链接。当我使用此关键字执行搜索时,该站点中的属性会显示,toronto正如您在此图像中看到的那样。

网站链接

下面的脚本可以解析不同属性的链接。但是,我不明白的是,除了从开发工具复制之外,我如何使用 lat 的值,long 。此外,我toronto在搜索框中使用过,但以下有效负载没有。我认为有效载荷内的经纬度代表城市。

import requests

link = "https://api2.realtor.ca/Listing.svc/PropertySearch_Post"

payload = {
    'ZoomLevel': '10',
    'LatitudeMax': '43.92411',
    'LongitudeMax': '-78.73025',
    'LatitudeMin': '43.49129',
    'LongitudeMin': '-80.02252',
    'Sort': '1-A',
    'PropertyTypeGroupID': '1',
    'PropertySearchTypeId': '1',
    'TransactionTypeId': '2',
    'Currency': 'CAD',
    'RecordsPerPage': '12',
    'ApplicationId': '1',
    'CultureId': '1',
    'Version': '7.0',
    'CurrentPage': '1'
}

with requests.Session() as s:
    s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
    r = s.post(link,data=payload)
    for item in r.json()['Results']:
        print(item['RelativeDetailsURL'])

如何在与任何自定义城市相关的有效载荷中使用 lat、long?

标签: pythonjsonpython-3.xweb-scrapingpython-requests

解决方案


纬度和经度确实代表城市。

'LatitudeMax': '46.88411',
'LongitudeMax': '-72.06525',
'LatitudeMin': '46.14629',
'LongitudeMin': '-70.57902',

在感兴趣的区域上形成一个正方形。因此,使用上述值,您将获得魁北克地区作为示例。


推荐阅读