import requests
from bs4 import BeautifulSoup


def get_home_soup(home_rel_url):
    """
    Accepts the relative URL for an individual home listing and returns a BeautifulSoup object.

    :param home_rel_url: str. Relative URL string that can be appended to the root 'https://www.redfin.com'.
                             E.g. '/CA/Oakland/9863-Lawlor-St-94605/home/1497266'
    :return: BeautifulSoup object for an individual listing's website.
    """

    url = 'https://www.redfin.com' + home_rel_url
    hdr = {'User-Agent': 'Mozilla/5.0'}
    response = requests.get(url, headers=hdr)
    assert response.status_code == 200, "HTML status code isn't 200 for {}.".format(home_rel_url)

    return BeautifulSoup(response.text, "lxml")