Imports System.IO
Imports System.Net
Imports System.Text
Public Class Form1
    Dim fwrite As FileStream
    Dim webstream As Stream
    Dim req As WebRequest
    Dim resp As WebResponse
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dataLen As Integer = 0
        Dim data(60000) As Byte
        req = WebRequest.Create(TextBox1.Text)
        fwrite = New FileStream(TextBox2.Text, FileMode.Create, FileAccess.Write)
        resp = req.GetResponse()
        webstream = resp.GetResponseStream()
        Dim fsize As Integer = 0
        Do
            dataLen = webstream.Read(data, 0, 1000)
            fsize = fsize + dataLen
            If dataLen = 0 Then Exit Do
            fwrite.Write(data, 0, dataLen)
        Loop
        TextBox3.Text = "file size : " & fsize
        resp.Close()
        fwrite.Close()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = "http://www.sanook.com/index.php"
        TextBox2.Text = "c:\data.htm"
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim fn As FileStream = New FileStream(TextBox2.Text, FileMode.Open)
        Dim sr As StreamReader = New StreamReader(fn, Encoding.Default)
        Dim a() As String
        Dim t As String
        Dim i As Integer = 0
        Do While sr.Peek() >= 0
            t = sr.ReadLine
            t = Replace(t, Chr(34), "")
            a = Split(t, "<img src=")
            If (a.Length > 1) Then
                a = Split(a(1), " ")
                If (a.Length > 1 And Mid(a(0), 1, 4) = "http") Then
                    If (i >= CInt(TextBox4.Text) And i <= CInt(TextBox5.Text)) Then
                        TextBox3.Text = TextBox3.Text + a(0)
                        TextBox3.Text = TextBox3.Text + vbCrLf
                    End If
                    i = i + 1
                End If
            End If
        Loop
        fn.Close()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim l() As String = Split(TextBox3.Text, vbCrLf)
        Dim fs As String = ""
        For j As Integer = 0 To l.Length - 1
            If (Len(l(j)) > 10) Then
                Dim ext() As String = Split(l(j), ".")
                Dim fwrite As FileStream
                fs = "c:\i" & Format(j, "0000") & "." & ext(ext.Length - 1)
                fwrite = New System.IO.FileStream(fs, FileMode.Create, FileAccess.Write)
                Dim req As WebRequest = WebRequest.Create(l(j))
                Dim resp As WebResponse = req.GetResponse()
                Dim webstream As Stream = resp.GetResponseStream()
                Dim dataLen As Integer = 0
                Dim data(8000) As Byte
                Do
                    dataLen = webstream.Read(data, 0, 1000)
                    If dataLen = 0 Then Exit Do
                    fwrite.Write(data, 0, dataLen)
                Loop
                resp.Close()
                fwrite.Close()
            End If
        Next
        Shell("explorer " & fs)
    End Sub
End Class
