selenium - 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 一次不加载页面如何加载整个页面并从视频中抓取所有评论
解决方案
推荐阅读
- angular - NgxAuthFirebaseUIModule 显示 ERROR NullInjectorError: R3InjectorError(AppModule)[ActivatedRoute -> ActivatedRoute -> ActivatedRoute]:
- angular - Fullcalendar 5 resourceLabelContent 返回承诺
- prettier - 什么 Prettier 规则将这个 JSX 分成多行?
- mongodb-query - MongoDb 计算日期查询
- authentication - 当前上下文中不存在名称“'_emailSender'”
- reactjs - 如何使用电子锻造在电子生产中添加额外的资源文件
- url - 链接最后一部分的名称
- java - DynamoDB 使用二级索引获取最后一个项目的计数
- validation - 如何验证 UPI Id 是否有效?
- sql - 更新从 Select 语句返回的值