如何使用 Idealista API 获取房地产数据? [英] How to get real estate data with Idealista API?

查看:73
本文介绍了如何使用 Idealista API 获取房地产数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 Idealista 网站的 API (https://www.idealista.com/) 来检索房地产数据的信息.

I've been trying to use the API of the website Idealista (https://www.idealista.com/) to retrieve information of real estate data.

由于我不熟悉 OAuth2,因此到目前为止我还无法获得令牌.我刚刚获得了 api 密钥、秘密和一些关于如何挂载 http 请求的基本信息.

Since I'm not familiarized with OAuth2 I haven't been able to obtain the token so far. I have just been provided with the api key, the secret and some basic info of how to mount the http request.

我希望能提供一个有关此 API 功能的示例(最好使用 Python),或者一些有关处理 OAuth2 和 Python 的更通用的信息.

I would appreciate an example (preferably in Python) of the functioning of this API, or else some more generic info about dealing with OAuth2 and Python.

推荐答案

经过几天的研究,我想出了一个基本的 Python 代码来从 Idealista API 检索房地产数据.

After some days of research I came up with a basic python code to retrieve real estate data from the Idealista API.

def get_oauth_token():
http_obj = Http()
url = "https://api.idealista.com/oauth/token"
apikey= urllib.parse.quote_plus('Provided_API_key')
secret= urllib.parse.quote_plus('Provided_API_secret')
auth = base64.encode(apikey + ':' + secret)
body = {'grant_type':'client_credentials'}
headers = {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8','Authorization' : 'Basic ' + auth}
resp, content = http_obj.request(url,method='POST',headers=headers, body=urllib.parse.urlencode(body))
return content

此函数将返回带有 OAuth2 令牌和会话时间(以秒为单位)的 JSON.之后,查询 API 就很简单了:

This function would return a JSON with the OAuth2 token and the session time in seconds. Afterwards, to query the API, it would be as simple as:

def search_api(token):
http_obj = Http()
url = "http://api.idealista.com/3.5/es/search?center=40.42938099999995,-3.7097526269835726&country=es&maxItems=50&numPage=1&distance=452&propertyType=bedrooms&operation=rent"
headers = {'Authorization' : 'Bearer ' + token}
resp, content = http_obj.request(url,method='POST',headers=headers)
return content

这一次,我们将在内容变量中找到我们正在寻找的数据,同样是 JSON.

This time the we would find in the content var the data we were looking for, again as a JSON.

这篇关于如何使用 Idealista API 获取房地产数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆