在Python/Selenium,如何抓取整个youtube评论?

In Python/Selenium, How to crawl whole youtube comment?

我想通过使用来分析与 YouTube 评论和国家/地区的相关性 Python/selenium

如果 YouTube 的电影包含太多评论,我们滚动 chrome 以搜索下一条评论。因此我在加载评论前停了 3 秒。

last_page_height = driver.execute_script("return document.documentElement.scrollHeight")

while True:
    driver.execute_script("window.scrollTo(0, document.documentElement.scrollHeight);")
    time.sleep(3.0)
    new_page_height = driver.execute_script("return document.documentElement.scrollHeight")
    if new_page_height == last_page_height:
        break
    last_page_height = new_page_height

html_source = driver.page_source
driver.close()
soup = BeautifulSoup(html_source, 'lxml')

但此代码不会抓取全部评论,只能抓取大约 1500 条评论。

Youtube 的每个配额限制为 1500 条评论。使用 Api 可以获得更多结果,例如:Youtube Data Api