mirror of
https://github.com/davidjohnbarton/crawler-google-places.git
synced 2025-12-12 16:38:45 +00:00
Fixed infinite scroll
This commit is contained in:
parent
84b4040a0b
commit
3b87790d07
|
|
@ -35,10 +35,10 @@ const getPageScrollInfo = (page, elementToScroll) => page.evaluate((elementToScr
|
|||
module.exports = async (page, maxHeight, elementToScroll = 'body') => {
|
||||
const maybeResourceTypesInfiniteScroll = ['xhr', 'fetch', 'websocket', 'other'];
|
||||
const stringifyScrollInfo = (scrollInfo) => {
|
||||
return `scrollTop=${scrollInfo.scrollTop}, ` +
|
||||
`clientHeight=${scrollInfo.clientHeight}, ` +
|
||||
`scrollHeight=${scrollInfo.scrollHeight}, ` +
|
||||
`maxHeight=${maxHeight}`;
|
||||
return `scrollTop=${scrollInfo.scrollTop}, `
|
||||
+ `clientHeight=${scrollInfo.clientHeight}, `
|
||||
+ `scrollHeight=${scrollInfo.scrollHeight}, `
|
||||
+ `maxHeight=${maxHeight}`;
|
||||
};
|
||||
const defaultScrollDelay = 3000;
|
||||
const defaultElementTimeout = 60000;
|
||||
|
|
@ -72,7 +72,6 @@ module.exports = async (page, maxHeight, elementToScroll = 'body') => {
|
|||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await page.waitForSelector(elementToScroll, { timeout: defaultElementTimeout });
|
||||
let scrollInfo = await getPageScrollInfo(page, elementToScroll);
|
||||
logInfo(`Infinite scroll started (${stringifyScrollInfo(scrollInfo)}).`);
|
||||
|
|
@ -121,8 +120,4 @@ module.exports = async (page, maxHeight, elementToScroll = 'body') => {
|
|||
}
|
||||
page.removeAllListeners('request');
|
||||
logInfo(`Infinite scroll finished (${stringifyScrollInfo(scrollInfo)} resourcesStats=${JSON.stringify(resourcesStats)})`);
|
||||
} catch (err) {
|
||||
// Infinite scroll should not break whole crawler
|
||||
logError('An exception thrown in infiniteScroll()', err);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user