使用python selenium的execute_script()的ScrollHeight大小返回一个未更改的结果

使用python selenium的execute_script()的ScrollHeight大小返回一个未更改的结果,python,selenium,Python,Selenium,代码: 结果: 图像内容是我当前的代码。我的目标是在youtube频道上获取所有视频数据。但目前我只有30个初始视频数据。执行一次逻辑后,它就完成了。换句话说,newHeight的大小等于Lastheight的大小。当然,execute_脚本(“window.scrollTo(0,document.documentElement.scrollHeight);”)code正确执行一次。为什么会出现这种结果 class Channel: def __init__(self):

代码:

结果:

图像内容是我当前的代码。我的目标是在youtube频道上获取所有视频数据。但目前我只有30个初始视频数据。执行一次逻辑后,它就完成了。换句话说,newHeight的大小等于Lastheight的大小。当然,
execute_脚本(“window.scrollTo(0,document.documentElement.scrollHeight);”)
code正确执行一次。为什么会出现这种结果

class Channel:
    def __init__(self):
        self.channelId = ''
        self.Home = ''
        self.Home_title = ''
        self.videoTab = ''
        self.chromedriver = '../chromedriver.exe'
        self.chromeBrowser = webdriver.Chrome(self.chromedriver)

    def __del__(self):
        self.chromeBrowser.quit()

def getVideoData(self):
    self.chromeBrowser.get(self.videoTab)
    lastHeight = self.chromeBrowser.execute_script("return document.documentElement.scrollHeight")
    print('lastHeight : ' + str(lastHeight))
    while True:
        self.chromeBrowser.execute_script("window.scrollTo(0, document.documentElement.scrollHeight);")
        self.chromeBrowser.implicitly_wait(0.5)
        newHeight = self.chromeBrowser.execute_script("return document.documentElement.scrollHeight")
        print('newHeight : ' + str(newHeight))
        if newHeight == lastHeight:
            break
        lastHeight = newHeight
    page = self.chromeBrowser.page_source
    html = BeautifulSoup(page, 'html.parser')
    for href in html.select('#thumbnail'):
        href.get('href')
    for video_title in html.select('#video-title'):
        print(video_title.text)
    print(len(html.select('#video-title')))

将代码/输出共享为文本,而不是图像[@Andersson]对不起,Andersson。我对stackoverflow不熟悉。因此,所有代码都不能显示为代码样式。我不明白上面为什么显示代码。请理解。