Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rightmove Postcode to ID

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!

like image 593
Mensa 23 Avatar asked Oct 14 '25 20:10

Mensa 23


1 Answers

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
like image 183
Andrej Kesely Avatar answered Oct 17 '25 09:10

Andrej Kesely