Python Selenium按向下箭头显示所有页面内容

New*_*wbe 2 python selenium

我使用webdriver(selenium和python)打开了一个网页.除非我按空格键8次或按住向下箭头,否则页面上的所有项目都不会加载.

driver.get('https://www.some-website.html')
driver.find_element_by_class_name('profiles').click()
Run Code Online (Sandbox Code Playgroud)

我用谷歌搜索了ActionChains的解决方案,但我无法找到解决方案.预先感谢您的帮助.

ale*_*cxe 7

按空格可能只是将页面滚动到最底部,这可能会触发加载其他内容.你可以做的是用延迟ActionChains()按8次SPACE :

import time

from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)
for _ in range(8):
    actions.send_keys(Keys.SPACE).perform()
    time.sleep(1)
Run Code Online (Sandbox Code Playgroud)

或者,您可以滚动到 "页脚"元素的视图(或底部的其他内容,具体取决于特定的网站):

footer = driver.find_element_by_tag_name("footer")
for _ in range(8):
    driver.execute_script("arguments[0].scrollIntoView();", footer)
    time.sleep(1)
Run Code Online (Sandbox Code Playgroud)

但这些都是猜测,很难提供可靠的工作解决方案,而不是在您正在使用的实际网页上实际尝试它们.