In [30]:
import requests
from bs4 import BeautifulSoup

r=requests.get("https://www.century21.com/real-estate/rock-springs-wy/LCWYROCKSPRINGS/")
c=r.content
#c

soup=BeautifulSoup(c,"html.parser")
#print(soup.prettify())

all=soup.find_all("div",{"class":"property-card-primary-info"})
all

len(all)

all[0].find("a",{"class":"listing-price"}).text.replace("\n","").replace(" ","")
Out[30]:
'$215,000'
In [123]:
price=[]
address=[]
city=[]
beds=[]
f_bath=[]
h_bath=[]
sqr=[]
for item in all:
    p=item.find("a", {"class":"listing-price"}).text.replace("\n","").replace(" ","")
    price.append(p)
    a=item.find("div",{"class":"property-address"}).text.replace("\n","").replace("  ","")
    a=a[1:]
    address.append(a)
    c=item.find("div",{"class":"property-city"}).text.replace("\n","").replace("  ","")
    city.append(c)
    try:
        b=item.find("div",{"class":"property-beds"}).find("strong").text
        
    except:
        b=None
    beds.append(b)
    try:
        f=item.find("div",{"class":"property-baths"}).find("strong").text
    
    except:
        f=None
    f_bath.append(f)
    try:
        h=item.find("div",{"class":"property-half-baths"}).find("strong").text
        
    except:
        h=None
    h_bath.append(h)
    try:
        s=item.find("div",{"class":"property-sqft"}).find("strong").text
        
    except:
        s=None
    sqr.append(s)
    print(p)
    print(c)
    print(a)
    print(b)
    print(f)
    print(h)
    print(s)
    

#print(price)
#print(address)
#print(city)
$215,000
Rock Springs WY 82901 
117 Agate Street
3
2
None
None
$225,000
Rock Springs WY 82901 
53Moxa Arch
None
None
None
None
$60,000
Rock Springs WY 82901 
805 McKeehan
1
1
None
1,034
$233,900
Rock Springs WY 82901 
600 Arrowhead Way
3
2
1
2,104
$485,000
Rock Springs WY 82901 
2801 Belgian
7
3
None
None
$205,000
Rock Springs WY 82901 
231 Angle St
3
2
None
942
$318,500
Rock Springs WY 82901 
3424 Darlington Avenue
3
2
None
None
$49,000
Rock Springs WY 82901 
912 8th St
2
1
None
728
$165,000
Rock Springs WY 82901 
304 Midway
3
2
None
1,056
$12,000
Rock Springs WY 82901 
T20N R95W Sec 17 N2SW4
None
None
None
None
$54,900
Rock Springs WY 82901 
418 P Street
5
4
None
2,674
$235,900
Rock Springs WY 82901 
1036 Oak Way
2
2
None
2,208
$169,900
Rock Springs WY 82901 
109 Agate Street
3
2
None
2,496
$164,900
Rock Springs WY 82901 
326 Liberty St
4
2
None
952
$108,000
Rock Springs WY 82901 
1023 8th Street
3
1
None
848
$324,000
Rock Springs WY 82901 
213 Morning Glory Way
4
None
None
None
$37,000
Rock Springs WY 82901 
1620 W 2nd St #19
3
2
None
1,296
$150,000
Rock Springs WY 82901 
1018 Pilot Butte
4
1
None
None
$217,500
Rock Springs WY 82901 
1029 Elm
4
None
None
None
$175,000
Rock Springs WY 82901 
1176 Palisades Ct
5
2
None
960
In [124]:
print(len(price))
print(len(address))
print(len(city))
print(len(beds))
print(len(f_bath))
print(len(h_bath))
print(len(sqr))
20
20
20
20
20
20
20
In [126]:
import pandas as pd
df=pd.DataFrame({"Price":price, "Address":address, "City":city, "Beds":beds, "Full baths":f_bath, "Half baths":h_bath, "Squarefoot":sqr}, columns=["Price","Address","City","Beds","Full baths","Half baths","Squarefoot"])
df
Out[126]:
Price Address City Beds Full baths Half baths Squarefoot
0 $215,000 117 Agate Street Rock Springs WY 82901 3 2 None None
1 $225,000 53Moxa Arch Rock Springs WY 82901 None None None None
2 $60,000 805 McKeehan Rock Springs WY 82901 1 1 None 1,034
3 $233,900 600 Arrowhead Way Rock Springs WY 82901 3 2 1 2,104
4 $485,000 2801 Belgian Rock Springs WY 82901 7 3 None None
5 $205,000 231 Angle St Rock Springs WY 82901 3 2 None 942
6 $318,500 3424 Darlington Avenue Rock Springs WY 82901 3 2 None None
7 $49,000 912 8th St Rock Springs WY 82901 2 1 None 728
8 $165,000 304 Midway Rock Springs WY 82901 3 2 None 1,056
9 $12,000 T20N R95W Sec 17 N2SW4 Rock Springs WY 82901 None None None None
10 $54,900 418 P Street Rock Springs WY 82901 5 4 None 2,674
11 $235,900 1036 Oak Way Rock Springs WY 82901 2 2 None 2,208
12 $169,900 109 Agate Street Rock Springs WY 82901 3 2 None 2,496
13 $164,900 326 Liberty St Rock Springs WY 82901 4 2 None 952
14 $108,000 1023 8th Street Rock Springs WY 82901 3 1 None 848
15 $324,000 213 Morning Glory Way Rock Springs WY 82901 4 None None None
16 $37,000 1620 W 2nd St #19 Rock Springs WY 82901 3 2 None 1,296
17 $150,000 1018 Pilot Butte Rock Springs WY 82901 4 1 None None
18 $217,500 1029 Elm Rock Springs WY 82901 4 None None None
19 $175,000 1176 Palisades Ct Rock Springs WY 82901 5 2 None 960
In [127]:
df.to_csv("Output.csv")