2016-11-18 95 views
1

正如我研究的最聰明的方式是使用API​​,但使用cURL時,我可以在輸出中找到所有需要的信息,但它有點混亂。如何grep來自YouTube頻道的URL

curl https://www.youtube.com/user/HowdiniGuru/videos | grep "watch?" 

返回包含視頻網址,所有需要的塊:

<h3 class="yt-lockup-title "><a class="yt-uix-sessionlink yt-uix-tile-link spf-link yt-ui-ellipsis yt-ui-ellipsis-2" dir="ltr" title="Breaking: MLA Sarwan Singh Phillaur resigned from SAD" aria-describedby="description-id-18618" data-sessionlink="ei=fHsvWKztM8OouALZlJ24Cg&amp;feature=c4-videos-u&amp;ved=CDkQlx4iEwism5ewqLPQAhVDFE4KHVlKB6comxw" href="**/watch?v=fDqv1-kYGPI**">Breaking: MLA Sarwan Singh Phillaur resigned from SAD</a><span class="accessible-description" id="description-id-18618"> - Duration: 43 seconds.</span></h3> 

但有困難,只/手錶?部件到達輸出。

curl https://www.youtube.com/user/HowdiniGuru/videos | grep "watch?" | cut -f4 -d"=" | grep class | cut -f1 -d'"' 

做這項工作,但它不是非常有效,因爲我可以想象。

回答

1

捲曲不是這個工作的工具:

lynx -dump -listonly -nonumbers https://www.youtube.com/user/HowdiniGuru/videos | 
grep watch 

Example

+1

工作就像一個魅力。 – Andy

1

使用curl https://www.youtube.com/user/HowdiniGuru/videos | grep -oh "/watch?v[^\"*]\+"僅匹配/watch...部件。

+0

捲曲的http:// youtubeurl | grep -oh「/ watch [^ *] \ +」仍然返回很多代碼 – Andy

+0

我更新了我的表達式以更好地匹配鏈接。 – Alden

相關問題