RightMove邮政编码到ID

发布于 2025-02-07 21:25:04 字数 447 浏览 2 评论 0 原文

我正在使用Python从RightMove刮擦一些数据。目前,我必须手动查找RightMove Post代码ID以生成URL。有没有一种方法通过API来执行此操作?

例如,对于邮政编码SY3 9EB,URL为:

所以我需要一种将邮政编码表映射到ID的方法,例如,

Postcode   ID
SY3 9EB    5E4203018

请提前感谢!

I am using Python to scrape some data from Rightmove. At the moment, I'm having to look up the rightmove postcode ID manually to generate the URL. Is there a way of doing this via the API?

For example, for postcode SY3 9EB, the URL is:
https://www.rightmove.co.uk/property-for-sale/find.html?locationIdentifier=POSTCODE%5E4203018

So I need a way of mapping a table of postcodes to ID, e.g.

Postcode   ID
SY3 9EB    5E4203018

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高跟鞋的旋律 2025-02-14 21:25:04

我不知道API,但是您可以使用不同的URL(带有邮政编码)获取位置ID。例如:

import json
import requests


# add postcode here:
l = "https://www.rightmove.co.uk/house-prices/sy3-9eb.html"


html_text = requests.get(l).text
data = re.search(r"__PRELOADED_STATE__ = ({.*?})<", html_text)
data = json.loads(data.group(1))

# print(json.dumps(data, indent=4))

location_id = data["searchLocation"]["locationId"]
final_link = "https://www.rightmove.co.uk/property-for-sale/find.html?locationIdentifier=POSTCODE^{}".format(
    location_id
)

print(final_link)

打印:

https://www.rightmove.co.uk/property-for-sale/find.html?locationIdentifier=POSTCODE^4203018

I'm not aware of Api, but you can use different URL (with postcode) to obtain the Location Id. For example:

import json
import requests


# add postcode here:
l = "https://www.rightmove.co.uk/house-prices/sy3-9eb.html"


html_text = requests.get(l).text
data = re.search(r"__PRELOADED_STATE__ = ({.*?})<", html_text)
data = json.loads(data.group(1))

# print(json.dumps(data, indent=4))

location_id = data["searchLocation"]["locationId"]
final_link = "https://www.rightmove.co.uk/property-for-sale/find.html?locationIdentifier=POSTCODE^{}".format(
    location_id
)

print(final_link)

Prints:

https://www.rightmove.co.uk/property-for-sale/find.html?locationIdentifier=POSTCODE^4203018
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文