Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function to automatically scroll to the bottom of the page
- async function autoScroll(page) {
- await page.evaluate(async () => {
- // use Promise to handle asynchronous scrolling
- await new Promise((resolve, reject) => {
- let totalHeight = 0; // initialize total height scrolled
- const distance = 100; // set distance to scroll each time
- // set interval to continuously scroll the page
- const scrollInterval = setInterval(() => {
- // calculate the total scroll height of the page
- const scrollHeight = document.body.scrollHeight;
- // scroll the page by the specified distance
- window.scrollBy(0, distance);
- // update the total height scrolled
- totalHeight += distance;
- // check if the total height scrolled is equal to or exceeds the scroll height of the page
- if (totalHeight >= scrollHeight) {
- // if so, clear the interval to stop scrolling
- clearInterval(scrollInterval);
- // resolve the Promise to indicate scrolling is complete
- resolve();
- }
- }, 100); // set interval duration
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement