Here is the URL of a song: https://pianomarvel.com/en/nextgen/home/78590/84. I’m trying to get the length of the window the song is in, using Selenium.
I have the following code
def scroll_down():
driver.execute_script("window.scrollBy(0, 1000)")
# Loop to scroll down in small increments
previous_height = 0
while True:
scroll_down() # Scroll down by 1000 pixels
time.sleep(2) # Give time for content to load
new_height = driver.execute_script("return document.documentElement.scrollHeight")
# Break if no more content is being loaded
if new_height == previous_height:
break
previous_height = new_height
print("Final height for {title}:", new_height)
But, regardless of the song, it is giving me the same song height.
I have tried asking ChatGPT for code. It also gave me another program option:
body_height = body_element.size['height']
time.sleep(3)
# Scroll down to the bottom of the page
while True:
# Scroll down by pressing END key
body_element.send_keys(Keys.END)
time.sleep(3) # Adjust sleep time as needed
# Get updated height of the body element
new_body_height = body_element.size['height']
time.sleep(3)
# Break the loop if the height does not increase anymore (reached the bottom)
if new_body_height == body_height:
break
time.sleep(3)
body_height = new_body_height
print(f"Height of {title}:", body_height)
New contributor
Carl Konopka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.