2

I am trying to auto-scroll the webpage for [this link][1] for a custom date range. After scrolling, I have to save the full HTML of the page manually.

At first, I am choosing a custom range (example 1-7 July 2022), as shown below.

[![enter image description here][2]][2]

Now, I am trying to auto-scroll this page using Console. For this, I am using setInterval function like this way,

var button=document.getElementById("paginationShowMoreText");
myTimer = setInterval(function(){ 
        button.click();
     }, 1000);

Then after a minute clearInterval(myTimer); to terminate setInterval. After running this in console, I expect that it would show all analysis between custom range.But, unfortunately, it gives me the repetition of 1st page. How can I get the entire scrolled page so that I can download the page as source? Is there any other way to auto-scroll for a certain range of data, any kind of suggestion would be helpful for me.

Thanks for your kind attention.

backlog
  • 55
  • 12

2 Answers2

1

Try this

var button = document.getElementById("paginationShowMoreText");
setInterval(function(){ 
    button.click();
    window.scrollTo(0, document.body.scrollHeight);
 }, 1000);
Vivek rao
  • 11
  • 2
  • Sorry to say, it gives the same repetitive output as like my code. – backlog Jul 30 '22 at 09:17
  • This solution seems to do the trick, no? The only caveat is that the additional data is loaded asynchronously, so the scrollTo happens before the data is finished loading. But as the 2 lines are executed every second it works nevertheless. – johey Aug 01 '22 at 13:06
  • 1
    Aaah, no, I see what you mean: it always fetches the same data. – johey Aug 01 '22 at 13:07
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 01 '22 at 13:08
0

The answer of Vivek is almost correct, but you need to re-query the button as its onclick attribute is changed after each click. (I've modified the query to make it a bit more precise: it fetches the anchor link instead of it's label)

So this should work as intended:

setInterval(function(){ 
    var button = document.querySelector('[data-action=listPaginationItems]');
    if (button) button.click();
    window.scrollTo(0, document.body.scrollHeight);
 }, 1000);
johey
  • 1,139
  • 1
  • 9
  • 25