`import requests
from bs4 import BeautifulSoup
import pandas as pd
Rental=[]
current_page=1
proceed=True
while(proceed):
url=f'https://www.residential.com/homesearch/for_rent/CA/Los_Angeles?show_views_counter=1&show_days_on_market=0&page={current_page}&sort=-listed_date'
response=requests.get(url)
html=response.text
soup=BeautifulSoup(html,'html.parser')
if soup.title.text=='404 Not Found':
proceed=False
else:
accomodation=soup.find('div',{'class':'container_listingsList__cLFTb'})
home=accomodation.find_all('a',{'class':'listing_listing__s6sYv'})
for house in home:
price=house.find('div',{'class':'listing_price__Btsti'}).text.strip()
area=house.find('div',{'class':'listing_details__D3EEd'}).text.strip()
adress=house.find('div',{'class':'listing_address__Xntl0'}).text.strip()
name=[]
try:
n=house.find_all('div',{'class':'agent-source_name__iAwOO'})[0]
name.append(n.text[13:].strip())
except:
name.append('Agent info not found')
current_page+=4
`import requests from bs4 import BeautifulSoup import pandas as pd Rental=[] current_page=1 proceed=True while(proceed):
Rental.append([name,adress,area,price])
df=pd.DataFrame(Rental,columns=['Name','Adress','Residential information','Price']) df.to_csv('C:/Users/DELL/Desktop/Python Projects/Python/Codes/houses.csv',index=False)
[Uploading Web Scraping Sample projects.pdf…]()