【发布时间】:2015-06-12 11:32:31
【问题描述】:
在以下网页上,我想在我的列表框中获取 youtube 视频的所有标题1
Dim webRequest As WebRequest = webRequest.Create("https://www.youtube.com/results?q=test")
Dim webresponse As WebResponse = webRequest.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(webresponse.GetResponseStream())
Dim youtube As String = sr.ReadToEnd
Dim r As New System.Text.RegularExpressions.Regex("title="".*""")
Dim matches As MatchCollection = r.Matches(youtube)
For Each itemcode As Match In matches
ListBox1.Items.Add(itemcode.Value.Split("""").GetValue(1))
但是,通过这段代码,我得到了标题,还有一堆其他的东西......
【问题讨论】:
-
您的代码不完整...如果您向我们展示“其他内容”也很棒。
-
YouTube 有一个 API,您可以使用它来搜索视频并获取标题和其他信息,而无需抓取 HTML 页面。 developers.google.com/youtube/v3
-
@theduck 太好了,会看看!
-
这是您想要的特定电话:developers.google.com/youtube/v3/docs/search/list。您需要使用 Google 控制台为自己创建一个 API 密钥,然后您可以进行以下调用:googleapis.com/youtube/v3/…{YOUR_API_KEY},您将获得格式良好的 JSON。
-
@theduck 感谢您的所有意见。使用 API 需要 C#?