我如何使用 javascript 或 php 为 youtube 生成一个 url,用于搜索特定用户帐户上的视频,并将最佳标题匹配放在顶部?
我正在使用这段代码:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
</head>
<script type="text/javascript">
function mysearch()
{
var elem=document.getElementById('inputsearchquery');
var url="http://www.youtube.com/user/QueenVEVO/videos?query="+encodeURIComponent(elem.value);
var win=window.open(url, '_blank');
win.focus();
}
</script>
<body>
<h2>Enter search string (user: Queen)</h2>
<input id="inputsearchquery" type="text" value="the show must go on">
<button type="button" onclick="mysearch()">Search</button>
</body>
唯一的问题是 youtube 没有将最佳标题匹配放在顶部!视频“The show must go on”排在第 13 位,我预计它会排在首位?
谁能告诉我如何更改 url,以便 youtube 将最匹配的标题放在首位?或者我真的必须使用 youtube api 来完成这项任务吗?
最佳答案
我不确定我是否理解你的问题,但你可以使用 GET 搜索。
像这样 http://www.youtube.com/results?search_query=the+show+must+go+on&oq=the+show+must+go+on
“search_query”部分可能来自您网站的用户。您必须将其解析为 GET 语法并将其发送到 youtube。然后,您可以获得结果的来源并使用正则表达式搜索您的字符串,也许还有高浏览量或类似的东西。
但我相信学习 youtube api 会为您节省更多时间和工作!
关于javascript - 为 youtube 搜索生成一个 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15829767/