【问题标题】:How to use API in idealista with python如何通过python在idealista中使用API
【发布时间】:2020-10-29 20:54:18
【问题描述】:

有没有办法在 python 中使用 Idealista Api 或更简单的方法? 我以前没试过这个。 我有 APIkey 和秘密,还有一个地籍代码列表,所以想获得每个代码的租金价格!

【问题讨论】:

  • 如果您已经尝试过,请通过发布适当的 URL 或代码来改进您的问题

标签: python api web-scraping


【解决方案1】:

您好,这适用于我使用 Python 3.8

首先你需要从 Idealista 获取令牌:

import json
import requests
import base64

def get_token():
    API_KEY= "YOUR_API_KEY"
    SECRET= "YOUR_SECRET"
    message = API_KEY + ":" + SECRET
    auth = "Basic " + base64.b64encode(message.encode("ascii")).decode("ascii")

    headers_dic = {"Authorization" : auth,
                   "Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8"}

    params_dic = {"grant_type" : "client_credentials",
                  "scope" : "read"}

    r = requests.post("https://api.idealista.com/oauth/token",
                      headers = headers_dic,
                      params = params_dic)

    bearer_token = json.loads(r.text)['access_token']

    return bearer_token

现在您可以使用该令牌访问搜索 api:

def get_search():
    headers_dic = {"Authorization" : "Bearer " + TOKEN,
                   "Content-Type" : "application/x-www-form-urlencoded"}

    params_dic = {"operation" : "rent",
                  "locationId" : "0-EU-ES-01",
                  "propertyType" : "homes"}

    r = requests.post("https://api.idealista.com/3.5/es/search",
                      headers = headers_dic,
                      params = params_dic)

    result_json = json.loads(r.text)

    return result_json

我发现西班牙的 locationId 从 0-EU-ES-01 变为 0-EU-ES-56。我没有尝试其他国家。

【讨论】:

    猜你喜欢
    • 2017-02-22
    • 2017-11-06
    • 2011-03-02
    • 2021-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多