在网页底部向下滚动 (selenium/python)

Scroll down at the bottom of a webpage (selenium/python)

我正在尝试从该网页获取所有图片:“https://www.airbnb.com/rooms/43871809/photos?guests=1&adults=1”

我正在使用 XPath 获取所有图像,但如果我不在底部向下滚动,则 XPath 只能获取 13 个图像,而它应该获取 39 个图像。 我正在使用以下代码:

   s = Service('D:\Selenium driver\chromedriver2.exe')
   driver = webdriver.Chrome(service=s)
   url = 'https://www.airbnb.com/rooms/43871809/photos?guests=1&adults=1'
   driver.get(url)
   time.sleep(4)
   driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
   images = driver.find_elements_by_xpath('//div[@class="_1oaklsk"]/div/div/picture/img')

我用其他方法来创建滚动动作。但我认为问题出在页面上。任何人都可以为我提供滚动或任何其他方法获取所有 39 张图像的解决方案。

P.S:我是新手,仍在学习,感谢您的帮助。谢谢

我尝试使用以下 xpath 并返回 39 作为图像的数量。

//div[@data-testid='photo-viewer-section']//a

代码:

#Imports Required:

from selenium.webdriver.common.by import By

driver.get("https://www.airbnb.com/rooms/43871809/photos?guests=1&adults=1")

images_count = driver.find_elements(By.XPATH,"//div[@data-testid='photo-viewer-section']//a")

print(len(images_count))

输出:

39