Created
June 19, 2019 00:40
-
-
Save arthurbailao/09dabce28bcb3090cbbab23c31a271cd to your computer and use it in GitHub Desktop.
Uber trips scraper
This file contains 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
const fetchRides = (offset = '0') => | |
fetch('https://riders.uber.com/api/getTripsForClient', { | |
method: 'POST', | |
body: JSON.stringify({ | |
limit: 50, | |
offset, | |
range: {fromTime: null, toTime: null}, }), headers: { | |
'x-csrf-token': document | |
.getElementById('__CSRF_TOKEN__') | |
.innerText.replace(/\\u0022/g, ''), | |
'content-type': 'application/json', | |
}, | |
}) | |
.then(response => response.json()) | |
.then(({data: {trips}}) => trips); | |
const fetchAllRides = (offset = '0', rides = []) => | |
fetchRides(offset).then( | |
({trips, pagingResult: {hasMore, nextCursor}}) => | |
hasMore | |
? fetchAllRides(nextCursor, rides.concat(trips)) | |
: rides.concat(trips), | |
); | |
const rides = await fetchAllRides() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
leaving this here temporarily before I make an userscript to automatically export the data