Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update airbnb_scraper.py #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions stl/scraper/airbnb_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def run(self, query: str, params: dict):
pagination['totalCount'], self.__geography['fullAddress'], params)
)
n_listings = 0
max_pages = 1
page = 1
data_cache = {}
while pagination.get('hasNextPage'):
while page <= max_pages:
self.__logger.info('Searching page {} for {}'.format(page, query))
listing_ids = self.__pdp.collect_listings_from_sections(data, self.__geography, data_cache)
for listing_id in listing_ids: # request each property page
Expand All @@ -67,11 +68,13 @@ def run(self, query: str, params: dict):
self.__logger.info(msg)
listings.append(listing)

self.__add_search_params(params, url)
items_offset = pagination['itemsOffset']
params.update({'itemsOffset': items_offset})
url = self.__explore.get_url(query, params)
data, pagination = self.__explore.search(url)
if pagination.get('hasNextPage'):
self.__add_search_params(params, url)
items_offset = pagination['itemsOffset']
params.update({'itemsOffset': items_offset})
url = self.__explore.get_url(query, params)
data, pagination = self.__explore.search(url)
max_pages+=1
page += 1

self.__persistence.save(query, listings)
Expand Down