【发布时间】:2014-03-29 08:10:58
【问题描述】:
所以我正在尝试从网站上抓取用户名并在此处遵循本教程
https://www.youtube.com/watch?v=FpAvBOhDrYk 第一部分
https://www.youtube.com/watch?src_vid=FpAvBOhDrYk第二部分
并关注了所有内容,但无法使其正常工作,但这是我使用的 vb.net 代码
-
导入 System.Text.RegularExpressions
公开课表1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://statigr.am/tag/anime") Dim response As System.Net.HttpWebResponse = Request.GetResponse Dim rs As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream()) Dim rssourcecode As String = rs.ReadToEnd '<a href="/hannahotaku">hannahotaku</a> Dim r As New System.Text.RegularExpressions.Regex("<a href=""/.*"">hannahotaku</a>") Dim matches As MatchCollection = r.Matches(rssourcecode) For Each itemcode As Match In matches ListBox1.Items.Add(itemcode.Value.Split("""").GetValue(1)) Next End Sub End Class
你可以看到我正在使用网站统计图 我试图抓取的来源是这个
<a href="/hannahotaku">hannahotaku</a>
请让我知道我做错了什么,因为我想刮
之间的部分(<a href="/**whatever username here**"></a>)
【问题讨论】:
-
尝试使用惰性版本:
"<a href=""/.*?"">hannahotaku</a>" -
试过了,列表框中什么也没有出现:/
-
我刚刚查看了您正在阅读的网站,但没有找到
hannahotaku...? -
那是因为它每秒更新一次,因为我想抓取页面上的每个用户名。
-
好吧,我在做一个疯狂的猜测:尝试
"<div><div>([^<]+)</div>"作为正则表达式并在循环中,而不是itemcode.Value.Split("""").GetValue(1)使用itemcode.Groups(1).Value