enter image description here。
下面是我的python代码。
get()
运行良好。
但是在执行execute_script("return document.body.scrollHeight")
之后,lastHeight
返回{newHeight
也返回0
。
它们为什么返回0
?在
def getVideoData(self):
self.chromeBrowser.get(self.videoTab)
lastHeight = self.chromeBrowser.execute_script("return document.body.scrollHeight")
print(lastHeight)
while True:
self.chromeBrowser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
self.chromeBrowser.implicitly_wait(0.5)
newHeight = self.chromeBrowser.execute_script("return document.body.scrollHeight")
print(newHeight)
if newHeight == lastHeight:
break
lastHeight = newHeight
图中显示了get()的正确结果。要显示图像,请单击“在此处输入图像说明”
我假设您正在尝试使用selenium滚动到页面的末尾。在分析这个问题时,我发现javascript
document.body.scrollHeight
有一个bug,它在类似于YouTube.com网站有浮动的web元素。参考Bug details。我尝试了document.documentElement.scrollHeight
,它看起来对这个页面很有用。在已经说过,下面的指令可以滚动到页面的末尾。在
^{pr2}$如果要删除
Chrome is being controlled by automated software
信息栏,请使用以下命令启动浏览器。在相关问题 更多 >
编程相关推荐