Update ApartmentHunter.py
This commit is contained in:
@@ -9,7 +9,7 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|||||||
|
|
||||||
#list of Cities
|
#list of Cities
|
||||||
Cities =["Dallas","Fort Worth","Arlington","Plano","Irving","Denton","Richardson","Grapevine"]
|
Cities =["Dallas","Fort Worth","Arlington","Plano","Irving","Denton","Richardson","Grapevine"]
|
||||||
St="tx"
|
state="tx"
|
||||||
baseurl="https://www.apartments.com/" #baseURL
|
baseurl="https://www.apartments.com/" #baseURL
|
||||||
search ="/2-bedrooms-under-1500" #search terms
|
search ="/2-bedrooms-under-1500" #search terms
|
||||||
search_dict = {
|
search_dict = {
|
||||||
@@ -75,13 +75,14 @@ def genSearch(city, state, search_dict):
|
|||||||
driver = webdriver.Chrome()
|
driver = webdriver.Chrome()
|
||||||
wait = WebDriverWait(driver, 20)
|
wait = WebDriverWait(driver, 20)
|
||||||
|
|
||||||
url = baseurl+'Dallas'+"-"+St+search
|
url = baseurl+'Dallas'+"-"+state+search
|
||||||
driver.get(url)
|
driver.get(url)
|
||||||
src = driver.page_source
|
src = driver.page_source
|
||||||
soup = BeautifulSoup(src, 'html.parser')
|
soup = BeautifulSoup(src, 'html.parser')
|
||||||
|
|
||||||
for city in Cities:
|
for city in Cities:
|
||||||
url = baseurl+city+"-"+St+search
|
url= genSearch(city, state, search_dict)
|
||||||
|
#url = baseurl+city+"-"+St+search
|
||||||
driver.get(url)
|
driver.get(url)
|
||||||
src = driver.page_source
|
src = driver.page_source
|
||||||
soup = BeautifulSoup(src, 'html.parser')
|
soup = BeautifulSoup(src, 'html.parser')
|
||||||
@@ -91,7 +92,6 @@ for city in Cities:
|
|||||||
ApartmentBeds = soup.find_all('p', class_='property-beds')
|
ApartmentBeds = soup.find_all('p', class_='property-beds')
|
||||||
ApartmentInfo= soup.find_all('div', class_="property-information") #finds all div elements with class of property-information and its children
|
ApartmentInfo= soup.find_all('div', class_="property-information") #finds all div elements with class of property-information and its children
|
||||||
ApartmentLink = [] #used to collect all href links
|
ApartmentLink = [] #used to collect all href links
|
||||||
print(city, len(Apartment))
|
|
||||||
for x in range(0,len(ApartmentInfo)): #go through all the div elements
|
for x in range(0,len(ApartmentInfo)): #go through all the div elements
|
||||||
ApartmentLink.append(ApartmentInfo[x].find_all('a')[0]['href']) # find all the a elements in each div and appends its href value to ApartmentLink
|
ApartmentLink.append(ApartmentInfo[x].find_all('a')[0]['href']) # find all the a elements in each div and appends its href value to ApartmentLink
|
||||||
for apartment, address, link in zip(Apartment, ApartmentAddr, ApartmentLink):
|
for apartment, address, link in zip(Apartment, ApartmentAddr, ApartmentLink):
|
||||||
@@ -99,5 +99,5 @@ for city in Cities:
|
|||||||
Name = apartment.contents[0]
|
Name = apartment.contents[0]
|
||||||
Addr = address.contents[0]
|
Addr = address.contents[0]
|
||||||
Web = link
|
Web = link
|
||||||
#print(Name + ", ", Addr + ", ", Web)
|
print(Name + ", ", Addr + ", ", Web)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user