我正试图向下滚动一个网站(没有/没有)“加载更多”按钮(它的意思是:您必须向下滚动直到最后以获取更多数据< / strong>)。然后,我使用硒向下滚动。我可以看到正在打开chrome浏览器并向下滚动网页,但是它仅读取114个元素中的36个元素。(如果不向下滚动,则有20个元素。)
有用的信息:
网页有20个divs元素,我一直在寻找它,并向下滚动获取所有20个divs。
向下滚动后,它应该具有114个divs元素,但只能获取36个。
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from random import randint
browser = webdriver.Chrome()
browser.get("http://127.0.0.1/index.html")
time.sleep(randint(0, 9))
elem = browser.find_element_by_tag_name("body")
no_of_pagedowns = 40
while no_of_pagedowns:
elem.send_keys(Keys.PAGE_DOWN)
time.sleep(randint(0, 4))
no_of_pagedowns-=1
html = browser.page_source
soup = BeautifulSoup(html, "html5lib")
mydivs = soup.findAll("div", {"class": "cars"})
...
如果将“ html5lib”参数更改为html.parser,则会崩溃。
我想念什么吗?我想向下滚动它,然后从选定的div中获取所有元素。
谢谢!