我可以在Youtube / watch?v = videolink上获取所有视频信息,但是我想从Youtube / results?search-query页面上获取链接和标题。
webCommandMetadata":{"url":"/watch?v=VIDEOID"}
我使用此正则表达式"/\/watch\?v=(.*?)[&\"]/i"
获得了视频网址
Output:VIDEOID
但是我无法获得标题
title":{"accessibility":{"accessibilityData":{"label":"#VIDEOTITLE"
因为源中的标签太多。是否有可能将所有内容从标题到正则表达式进行正则表达式,然后像#VIDEOTITLE
这样输出?或者以其他方式获取它?
答案 0 :(得分:0)
(来自YouTube数据API文档)
首先获取结果,然后您可以从每个视频中获取标题
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
));
// Add each result to the appropriate list, and then display the lists of
// matching videos, channels, and playlists.
foreach ($searchResponse['items'] as $searchResult) {
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videos .= sprintf('<li>%s (%s)</li>',
$searchResult['snippet']['title'], $searchResult['id']['videoId']);
break;
case 'youtube#channel':
$channels .= sprintf('<li>%s (%s)</li>',
$searchResult['snippet']['title'], $searchResult['id']['channelId']);
break;
case 'youtube#playlist':
$playlists .= sprintf('<li>%s (%s)</li>',
$searchResult['snippet']['title'], $searchResult['id']['playlistId']);
break;
}
}