Skip to content

Instantly share code, notes, and snippets.

@ShayanRiyaz
Created April 24, 2020 10:35
Show Gist options
  • Save ShayanRiyaz/461019b3da553703bb022d38fd25f87b to your computer and use it in GitHub Desktop.
Save ShayanRiyaz/461019b3da553703bb022d38fd25f87b to your computer and use it in GitHub Desktop.
url = requests.get('https://www.rentcafe.com/average-rent-market-trends/us/ca/los-angeles/').text
soup = BeautifulSoup(url,"html.parser")
table = soup.find('table',id="MarketTrendsAverageRentTable")
pr = table.find_all('td')
nh = table.find_all('th')
price = []
neighbourhood = []
for i in range(0, len(pr)):
price.append(pr[i].text.strip())
neighbourhood.append(nh[i+2].text.strip())
df_rent = pd.DataFrame(data=[neighbourhood, price]).transpose()
df_rent.columns = ['Neighbourhood', nh[1].text]
df_rent[(df_rent['Neighbourhood']=='Harvard Heights') | (df_rent['Neighbourhood']=='Korea Town')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment