SoloHombs / Data-Analytics

All Data Analytics Dashboards
0 stars 0 forks source link

Webscraping Projects using Beautiful #1

Open SoloHombs opened 3 months ago

SoloHombs commented 3 months ago

`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

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…]()