Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scrape Rightmove
import json
from bson import json_util # pip install pymongo
from datetime import datetime
from rightmove_webscraper import rightmove_data
class rightmove_list(list):
def __init__(self, rightmove_object_results):
new_list = []
for key in rightmove_object_results.keys():
if not new_list:
new_list = [{} for x in rightmove_object_results[key]]
for i, v in enumerate(rightmove_object_results[key]):
new_list[i][key] = self.__fix_datetime(v)
super().__init__(new_list)
def __fix_datetime(self, val):
if isinstance(val,datetime):
return val.strftime('%Y-%m-%dT%H:%M:%S.%f')
return val
url = "https://www.rightmove.co.uk/property-for-sale/find.html?locationIdentifier=REGION%5E85329&minBedrooms=2&maxPrice=450000&radius=0.25&sortType=6&includeSSTC=false"
rightmove_object = rightmove_data(url)
# print(rightmove_object.get_results.to_json())
print(json.dumps(rightmove_list(rightmove_object.get_results)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment