首页 > 解决方案 > youtube selenium 评论抓取

问题描述

#open the webpage
driver.get("https://www.youtube.com/watch?v=trsklC1i0Js")


C =pd.DataFrame()

          
all_noc = driver.find_elements_by_xpath('/html/body/ytd-app/div/ytd-page-manager/ytd-watch-flexy/div[5]/div[1]/div/ytd-comments/ytd-item-section-renderer/div[1]/ytd-comments-header-renderer/div[1]/h2/yt-formatted-string/span[1]')
all_noc = [x.text for x in all_noc]
noc = pd.Series(all_noc)
   
    
all_comments = driver.find_elements_by_xpath('//*[@id="content-text"]')
all_comments = [x.text for x in all_comments]
comments = pd.Series(all_comments)
    
    
    


    

df = pd.DataFrame({"No. Of Comments":noc, "Comments":comments})
C = C.append(df) 
time.sleep(2)
C    

我想提取视频上的所有评论有超过 300 条评论和 YouTube 一次不加载页面如何加载整个页面并从视频中抓取所有评论

标签: seleniumweb-scrapingyoutubecomments

解决方案


推荐阅读