这是对我有用的简短代码:
SCROLL_PAUSE_TIME = 20# Get scroll heightlast_height = driver.execute_script("return document.body.scrollHeight")while True: # Scroll down to bottom driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # Wait to load page time.sleep(SCROLL_PAUSE_TIME) # Calculate new scroll height and compare with last scroll height new_height = driver.execute_script("return document.body.scrollHeight") if new_height == last_height: break last_height = new_heightposts = driver.find_elements_by_class_name("post-text")for block in posts: print(block.text)


