2024-05-20 03:42:54 发布
网友
有没有一种方法可以在python中使用理想化Api,还是一种更简单的方法? 我以前没试过这个。 我有钥匙和秘密,还有一份地籍代码清单,所以想知道每个代码的租金
嗨,这对我使用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。我没有尝试其他国家
0-EU-ES-01
0-EU-ES-56
嗨,这对我使用Python 3.8很有用
首先,您需要从Idealista获得代币:
使用该令牌,您现在可以访问搜索api:
我发现对于西班牙,locationId从
0-EU-ES-01
到0-EU-ES-56
。我没有尝试其他国家相关问题 更多 >
编程相关推荐