added function for dynamic search generation
This commit is contained in:
@@ -12,11 +12,63 @@ Cities =["Dallas","Fort Worth","Arlington","Plano","Irving","Denton","Richardson
|
||||
St="tx"
|
||||
baseurl="https://www.apartments.com/" #baseURL
|
||||
search ="/2-bedrooms-under-1500" #search terms
|
||||
search_dict = {
|
||||
"min_rent" : 0,
|
||||
"max_rent" : 0,
|
||||
"min_bed" : 0,
|
||||
"max_bed" : 0,
|
||||
"apartments" : True,
|
||||
"houses" : False,
|
||||
"condos" : False,
|
||||
"townhomes" : False,
|
||||
"mid" : "", #move-in date
|
||||
"bathroom" : 0 # 0-3
|
||||
}
|
||||
|
||||
def genSearch(city, state, search_dict):
|
||||
search = "" #base search
|
||||
# type parameter
|
||||
if not (search_dict['apartments'] and search_dict['houses'] and search_dict['condos'] and search_dict['townhomes']):
|
||||
if search_dict['apartments']:
|
||||
search = f"{search}apartments-"
|
||||
if search_dict['houses']:
|
||||
search = f"{search}houses-"
|
||||
if search_dict['condos']:
|
||||
search = f"{search}condos-"
|
||||
if search_dict['townhomes']:
|
||||
search = f"{search}townhomes-"
|
||||
if len(search) > 0:
|
||||
search = search[:-1] + "/"
|
||||
# next add city and state
|
||||
search = search + city + "-" + state + "/"
|
||||
|
||||
# next add bedrooms
|
||||
if search_dict['min_bed'] and search_dict['max_bed']:
|
||||
search = f"{search}{search_dict['min_bed']}-to-{search_dict['max_bed']}-bedrooms-"
|
||||
elif search_dict['min_bed']:
|
||||
search = f"{search}min-{search_dict['min_bed']}-bedrooms-"
|
||||
elif search_dict['max_bed']:
|
||||
search = f"{search}max-{search_dict['max_bed']}-bedrooms-"
|
||||
|
||||
# next add bathrooms
|
||||
if search_dict['bathroom']:
|
||||
search = f"{search}{search_dict['bathroom']}-bathrooms-"
|
||||
# finally add price range
|
||||
if search_dict['min_rent'] and search_dict['max_rent']:
|
||||
search = f"{search}{search_dict['min_rent']}-to-{search_dict['max_rent']}-"
|
||||
elif search_dict['min_rent']:
|
||||
search = f"{search}over-{search_dict['min_rent']}-"
|
||||
elif search_dict['max_rent']:
|
||||
search = f"{search}under-{search_dict['max_rent']}-"
|
||||
|
||||
return search[:-1]
|
||||
|
||||
#Configure the WebDriver
|
||||
#chrome_options = Options()
|
||||
#chrome_options.add_argument("disable-extensions")
|
||||
#chrome_options.add_argument("disable-gpu")
|
||||
#chrome_options.add_argument("headless")
|
||||
|
||||
driver = webdriver.Chrome()
|
||||
wait = WebDriverWait(driver, 20)
|
||||
#driver = webdriver.Edge()
|
||||
@@ -58,3 +110,4 @@ print(ApartmentLink)
|
||||
# Name = apartment.contents[0]
|
||||
# Addr = address.contents[0]
|
||||
# print(Name + ", ", Addr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user