【发布时间】:2022-06-22 16:47:30
【问题描述】:
我正在尝试使用 selenium 向下滚动谷歌地图页面,但无法这样做。我已经尝试了这里写的所有东西: Scroll down google maps webpage using selenium python
这是我的代码:
def scroll(self):
SCROLL_PAUSE_TIME = 5
# Get scroll height
last_height = self.execute_script("return document.body.scrollHeight")
number = 0
while True:
number = number+1
# Scroll down to bottom
ele = self.find_element_by_css_selector('div[jstcache="211"]')
print(ele)
self.execute_script('arguments[0].scrollBy(0, 500)', ele)
# Wait to load page
time.sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
print(f'last height: {last_height}')
ele = self.find_element_by_css_selector('div[jstcache="211"]')
new_height = self.execute_script("return arguments[0].scrollHeight", ele)
print(f'new height: {new_height}')
if number == 5:
break
if new_height == last_height:
break
print('cont')
last_height = new_height
但不知道如何向下滚动。
请帮忙!!
【问题讨论】:
-
你自己试过了吗?你有什么错误吗?我们可以看看你的代码吗?
-
请提供足够的代码,以便其他人更好地理解或重现问题。
-
@Akzy 我已经添加了代码,请看看有什么问题