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

在Python/Selenium中,如何抓取整个youtube评论?,python,selenium,beautifulsoup,youtube,web-crawler,Python,Selenium,Beautifulsoup,Youtube,Web Crawler,我想用以下方法分析YouTube评论和国家的相关性 Python/selenium 如果YouTube的电影包含太多评论,我们会滚动chrome搜索下一条评论。因此,我停止3秒钟,直到加载注释 last_page_height = driver.execute_script("return document.documentElement.scrollHeight") while True: driver.execute_script("window.scrollTo(0, docum

我想用以下方法分析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可以获得更多的结果,例如:

您需要从所选页面下载所有
注释
?@code\u可以有100/1000条注释,解决方案将有点取决于您处理的评论数量。@ZarakiKenpachi是的,我需要下载alllcomments@DebanjanB我将在youtube上抓取有大约500000条评论的BTS页面。我的代码问题从500,00条评论中抓取1500条评论谢谢你的回答,我将很快尝试学习YouTube Api。