Last active
July 27, 2018 18:58
-
-
Save ishan-marikar/0496b1a423f61b211afed75dfac9f00a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async *scraper() { | |
let noMorePages = false; | |
let currentPageURL = this._searchURL; | |
while (!noMorePages) { | |
try { | |
let listingsForCurrentPage = await this._getListingsFromPage( | |
currentPageURL | |
); | |
const isLimited = | |
this._maxNumberOfPages && | |
this._maxNumberOfPages === this._currentPageNumber; | |
const isLastPage = | |
listingsForCurrentPage && !listingsForCurrentPage.hasNext; | |
if (isLimited || isLastPage) { | |
noMorePages = !noMorePages; | |
return listingsForCurrentPage.listings; | |
} else { | |
yield listingsForCurrentPage.listings; | |
currentPageURL = listingsForCurrentPage.hasNext; | |
} | |
} catch (exception) { | |
throw exception; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.