Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added image_url of the first listing image to the output table #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rightmove_webscraper/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def _get_page(self, request_content: str, get_floorplans: bool = False):
xp_agent_urls = """//div[@class="propertyCard-contactsItem"]\
//div[@class="propertyCard-branchLogo"]\
//a[@class="propertyCard-branchLogo-link"]/@href"""
xp_image_urls = """//div[@class="propertyCard-img "]//img/@src"""

# Create data lists from xpaths:
price_pcm = tree.xpath(xp_prices)
Expand All @@ -180,6 +181,7 @@ def _get_page(self, request_content: str, get_floorplans: bool = False):
base = "http://www.rightmove.co.uk"
weblinks = [f"{base}{tree.xpath(xp_weblinks)[w]}" for w in range(len(tree.xpath(xp_weblinks)))]
agent_urls = [f"{base}{tree.xpath(xp_agent_urls)[a]}" for a in range(len(tree.xpath(xp_agent_urls)))]
image_urls = tree.xpath(xp_image_urls)

# Optionally get floorplan links from property urls (longer runtime):
floorplan_urls = list() if get_floorplans else np.nan
Expand All @@ -197,11 +199,11 @@ def _get_page(self, request_content: str, get_floorplans: bool = False):
floorplan_urls.append(np.nan)

# Store the data in a Pandas DataFrame:
data = [price_pcm, titles, addresses, weblinks, agent_urls]
data = [price_pcm, titles, addresses, weblinks, agent_urls, image_urls]
data = data + [floorplan_urls] if get_floorplans else data
temp_df = pd.DataFrame(data)
temp_df = temp_df.transpose()
columns = ["price", "type", "address", "url", "agent_url"]
columns = ["price", "type", "address", "url", "agent_url", "image_url"]
columns = columns + ["floorplan_url"] if get_floorplans else columns
temp_df.columns = columns

Expand Down