技术咨询:如何导出任意YouTube频道的视频列表(标题、链接、发布日期)
解决方案
我之前也碰到过类似的困扰——免费版Screaming Frog默认不会抓取YouTube的发布日期,而且Chrome Scraper扩展如果规则没设对,也容易漏掉这个关键字段。下面几个通用方法,适用于所有YouTube频道,亲测有效:
方法1:优化Screaming Frog免费版的自定义提取规则
免费版其实支持自定义DOM提取,只要找对YouTube页面里发布日期的定位:
- 打开Screaming Frog,进入Configuration > Custom > Extraction
- 点击"Add",设置第一条规则:
- Name:
Video Publish Date - CSS Path:
meta[property="article:published_time"] - Extract:
Attribute,选择content
- Name:
- 再添加一条备用规则(应对部分页面结构差异):
- Name:
Video Publish Date Fallback - CSS Path:
#info-strings yt-formatted-string - Extract:
Text
- Name:
- 开启JavaScript渲染(Configuration > Spider > Rendering > Enable JavaScript),因为YouTube页面是动态渲染的
- 爬取时输入频道的视频列表URL(比如
https://www.youtube.com/c/[ChannelName]/videos),爬完后在Custom标签页就能看到完整的发布日期数据
方法2:用Python脚本实现通用爬取(最可靠)
如果想完全自定义且不受工具限制,用Python写个简单脚本就行,不需要付费工具,适用于任何频道:
import requests from bs4 import BeautifulSoup import json import time def get_youtube_videos(channel_url): # 配置请求头,避免被反爬拦截 headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"} time.sleep(2) # 简单延迟,降低反爬风险 response = requests.get(channel_url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') # 提取页面中存储视频信息的JSON数据 script_tags = soup.find_all('script') target_data = None for script in script_tags: if 'ytInitialData' in script.text: data_text = script.text.split('window["ytInitialData"] = ')[1].split(';')[0] target_data = json.loads(data_text) break # 解析视频标题、链接和发布日期 videos = [] if target_data: content_items = target_data['contents']['twoColumnBrowseResultsRenderer']['tabs'][1]['tabRenderer']['content']['richGridRenderer']['contents'] for item in content_items: if 'richItemRenderer' in item: video_info = item['richItemRenderer']['content']['videoRenderer'] video_title = video_info['title']['runs'][0]['text'] video_link = f"https://www.youtube.com/watch?v={video_info['videoId']}" publish_date = video_info['publishedTimeText']['simpleText'] videos.append({ 'title': video_title, 'link': video_link, 'publish_date': publish_date }) return videos # 使用示例:替换成目标频道的视频列表URL channel_videos_url = "https://www.youtube.com/c/Google/videos" videos = get_youtube_videos(channel_videos_url) for vid in videos: print(f"标题: {vid['title']}\n链接: {vid['link']}\n发布日期: {vid['publish_date']}\n---")
- 这个脚本通过解析YouTube页面的初始JSON数据,不需要模拟浏览器,速度快且稳定
- 如果碰到反爬限制,可以适当延长延迟时间,或者轮换几个不同的User-Agent
方法3:修正Chrome Scraper扩展的抓取规则
如果坚持用Chrome Scraper,调整规则就能精准抓到发布日期:
- 打开Scraper扩展,点击"Create new scraper"
- 设置Selector为
meta[property="article:published_time"],提取content属性作为发布日期 - 或者针对视频页面的日期展示元素,用Selector
#info-strings yt-formatted-string提取文本内容 - 确保抓取范围设置为"Follow links"并指定频道视频列表的URL,扩展会自动遍历所有视频页面并提取对应字段
内容的提问来源于stack exchange,提问作者misaligar




