我试图从youtube或谷歌获得第一个youtube链接,但我无法让它工作。有人可以帮帮我吗?
Dim m As New Regex("<a href=""/watch?v=.*"""
)Dim request2 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://www.youtube.com/results?search_query=" + ListBox1.SelectedItem + " " + ListBox2.SelectedItem)
Dim responseyoutube As System.Net.HttpWebResponse = request2.GetResponse TextBox2.Text = (request2.Address.ToString) Dim sr As System.IO.StreamReader = New System.IO.StreamReader(responseyoutube.GetResponseStream()) Dim rssourcecodey As String = sr.ReadToEnd Dim matches As MatchCollection = m.Matches(rssourcecodey) TextBox1.Text = rssourcecodey For Each itemcode2 As Match In matches youtube = itemcode2.Value.Split("=").GetValue(1) ListBox2.Items.Add(youtube)
答案 0 :(得分:1)
?
是regex中的一个特殊元字符,它将前一个标记作为可选标记(不是*
或+
之后的标记)。因此,您需要按顺序转义?
符号才能匹配文字?
符号。
Dim m As New Regex("<a href=""/watch[?]v=.*""")
OR
Dim m As New Regex("<a href=""/watch\\?v=.*""")