【发布时间】:2018-04-18 19:49:45
【问题描述】:
我是新手。我想知道如何使用 BeautifulSoup 抓取 YouTube cmets。我被这里击中了。谁能帮我写代码。
这是我写的:
import requests
from bs4 import BeautifulSoup
r = requests.get("https://www.youtube.com/watch?v=kffacxfA7G4"
req =r.conten
soup = BeautifulSoup(req,'html.parser')
print(soup.prettify())
all = soup.find_all('div',{'id' : 'contents'})
我被困在这里没有得到任何输出,检查它显示 cmets 的 wb 页面有 id = contents
【问题讨论】:
-
这是学习
BeautifulSoup,还是需要和Youtube互动?你可以使用 Youtube 的 API - developers.google.com/youtube/v3/docs/comments/list -
嗨,@Robert Seaman。我正在学习
BeautifulSoup并试图让 youtube cmets 练习。我觉得很难做到。你能帮我解决这个问题吗? -
有更容易学习的页面
BeautifulSoup。像 youtube 这样更高级的网站通常通过 javascript 加载页面,因此如果您只使用requests.get,您将不会看到太多数据。也许尝试使用w3schools.com或example.com? -
另外,请格式化你的代码,这个sn-p不能通过复制粘贴运行,因为它不完整
标签: python python-3.x web-scraping beautifulsoup