BASH 从 youtube html 文件中提取链接

BASH extract links from youtube html file

我正在尝试在我的树莓派上制作 YouTube 音乐播放器,但我一直停留在这一刻:

Wget 正在下载站点,例如:https://www.youtube.com/results?search_query=test 到文件 output.html

该站点中的链接保存在这样的字符串中:<a href="/watch?v=DDzfeTTigKo"

现在当我尝试 grep 它们时 cat site | grep -B 0 -A 0 watch?v=

它从那个文件中打印出文本墙,我只想要像我上面提到的那样的特定行。我希望它保存在文件 site2

这可能吗?

用 GNU grep 试试:

grep -o '"/watch?v=[^"]*"' file.html