抓取YouTube视频观看次数

时间:2019-07-01 20:42:46

标签: python beautifulsoup youtube screen-scraping

我有一个https://www.youtube.com/watch?v=ywZevdHW5bQ这样的youtube视频链接列表,我需要使用BeautifulSoup和请求库抓取观看次数

2 个答案:

答案 0 :(得分:0)

preserve_hostname: true
fqdn: my-host
hostname: my-host

打印:

import requests
from bs4 import BeautifulSoup

url = 'https://www.youtube.com/watch?v=ywZevdHW5bQ'

soup = BeautifulSoup(requests.get(url).text, 'lxml')

print(soup.select_one('meta[itemprop="interactionCount"][content]')['content'])

答案 1 :(得分:0)

另一种方法是让自己获得一个Youtube API密钥,然后使用videos/list api端点获取有关视频的信息,然后使用响应来提取viewCount

  1. https://developers.google.com/youtube/v3/quickstart/python
  2. https://developers.google.com/youtube/v3/docs/videos/list
  3. https://developers.google.com/youtube/v3/docs/videos#resource