프로그래밍언어/VB.NET

MNET정규식연습

부산딸랑이 2013. 1. 24. 06:21
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Text.Regularexpressions
Imports System.Threading
Public Class Form1
Private wReq As HttpWebRequest
Private Regex As Regex
Private Matches, Matches2, Matches3, MatchesIMG As MatchCollection
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Size = New Size(700, 700)
ImageList1.ImageSize = New Size(60, 60)
CheckForIllegalCrossThreadCalls = False
ListView1.Columns.Add("순위", 100)
ListView1.Columns.Add("제목", 300)
ListView1.Columns.Add("가수", 200)
ListView1.Dock = DockStyle.Fill
ListView1.View = View.Details
'ListView1.SmallImageList = ImageList1
ListView1.FullRowSelect = True
gogogo()
End Sub
Private Function gogogo() As Object

wReq = DirectCast(WebRequest.Create(("http://mnet.interest.me/chart/TOP100/2012110622")), HttpWebRequest)
wReq.Method = "GET"
Dim Html소스 As String = New StreamReader(Me.wReq.GetResponse.GetResponseStream, Encoding.UTF8).ReadToEnd
Dim 정규식1 As New Regex("s=""music"">(.*?)</a>", RegexOptions.IgnoreCase)
Dim 정규식2 As New Regex("""_self"">(.+?)</a> /", RegexOptions.IgnoreCase)
Dim 정규식3 As New Regex("target=""_self""><img src=(.*?) alt="""onerror=", RegexOptions.IgnoreCase)
Dim 정규식4 As New Regex("(.*?)</a>.*?title=""(.*?)""", RegexOptions.IgnoreCase)
Matches = 정규식1.Matches(Html소스)
Matches2 = 정규식2.Matches(Html소스)
MatchesIMG = 정규식3.Matches(Html소스)
' MsgBox(MatchesIMG.Item(5).Groups.Item(1).ToString)

For i As Integer = 0 To 49
wReq = WebRequest.Create(MatchesIMG.Item(i + 2).Groups.Item(1).ToString)
ImageList1.Images.Add(Image.FromStream(wReq.GetResponse.GetResponseStream))

ListView1.Items.Add(i + 1)
ListView1.Items.Item(i).SubItems.Add(Me.Matches.Item((i + 2)).Groups.Item(1).ToString)
Dim a As String = Matches2.Item((i + 2)).Groups.Item(1).ToString
Matches3 = 정규식4.Matches(a)
If (a.Length > 50) Then
Dim 초과1 As String = Me.Matches3.Item(0).Groups.Item(1).ToString
Dim 초과2 As String = Me.Matches3.Item(0).Groups.Item(2).ToString
Me.ListView1.Items.Item(i).SubItems.Add((초과1 & " & " & 초과2))
Else
Me.ListView1.Items.Item(i).SubItems.Add(a)
End If

 

 

주소를 http://mnet.interest.me/chart/top100/chart.asp?chartDate= 로 바꾸면 됩니다..      




Next

Return vbEmpty
End Function





End Class