Hi guys I am new to Selenium and Python. I was just scraping the site pagalguy website. I know how to scroll down to the bottom of the page but what I need is to scroll down step by step so that the Selenium will click all the readmore buttons,but I don't know how to scroll down step by step like that so I hard coded it like following one
browser.execute_script("window.scrollTo(0,300);")
browser.find_element_by_link_text("Read More...").click()
browser.execute_script("window.scrollTo(300,600);")
browser.find_element_by_link_text("Read More...").click()
browser.execute_script("window.scrollTo(600,900);")
browser.find_element_by_link_text("Read More...").click()
browser.execute_script("window.scrollTo(900,1200);")
browser.find_element_by_link_text("Read More...").click()
browser.execute_script("window.scrollTo(1200,1500);")
browser.find_element_by_link_text("Read More...").click()
browser.execute_script("window.scrollTo(1500,1800);")
browser.find_element_by_link_text("Read More...").click()
browser.execute_script("window.scrollTo(1800,2100);")
browser.find_element_by_link_text("Read More...").click()
browser.execute_script("window.scrollTo(2100,2500);")
browser.find_element_by_link_text("Read More...").click()
it goes on .......
I tried automating it using a while loop but it resulted in error, the above one works but I want it short and looped so that I can use it for all the other pages with different page length.
initial_value = 0
next_value = 300
while next_value<300000:
browser.execute_script("window.scrollTo(initial_value,next_value);")
browser.find_element_by_link_text("Read More...").click()
initial_value=next_value
next_value+=300
JavascriptException: Message: ReferenceError: initial_value is not defined
But I have defined the value, I think I explained what I am actually trying to do, I want to automatically scroll down and click all the readmore buttons and then I will get the full text content