webpage loader

Installer of Visual Basic .net : requestwebimage1i.zip 229 KB

Imports System.io
Imports System.Net
Imports System.Text
Public Class Form1
Dim htmlfile As String = "c:\web.htm"
Private Sub Form1_Load( ...
    ComboBox1.Items.AddRange(New Object() { _ "http://truehits.net", _ "http://www.manager.co.th/home/default.html", _ "http://www.tourthai.com", _ "http://www.siamcomic.com", _ "http://www.hunsa.com", _ "http://www.mthai.com", _ "http://www.thaiall.com/index.php", _ "http://www.sanook.com/narrow"}) ComboBox1.Text = ComboBox1.Items.Item(0) TextBox2.Text = ComboBox1.Items.Item(0) DataGridView1.Columns.Add("no", "no") DataGridView1.Columns.Add("image link", "image link") DataGridView1.Columns.Add("local file", "local file") TextBox1.Text = "Webpage Loader Version 1.0" & Chr(13) & Chr(10) TextBox1.Text &= "Updated : February 7,2008" & Chr(13) & Chr(10) TextBox1.Text &= "Programmer by Burin Rujjanapan" & Chr(13) & Chr(10) TextBox1.Text &= "webmaster@thaiall.com" resize_form() r1.Select()
End Sub
Sub resize_form()
    TextBox1.Width = Me.Width - 285 DataGridView1.Columns.Item(0).Width = 30 DataGridView1.Columns.Item(1).Width = DataGridView1.Width - 190 DataGridView1.Columns.Item(2).Width = 100 DataGridView1.Width = Me.Width - 25 WebBrowser1.Width = Me.Width - 25 WebBrowser1.Height = Me.Height - 250
End Sub
Private Sub ComboBox1_SelectedIndexChanged( ...
    TextBox2.Text = ComboBox1.Text
End Sub
Private Sub Form1_Resize( ...
Try : resize_form() : Catch ex As Exception : End Try End Sub
Private Sub DataGridView1_CellClick( ...
    Try Dim cur As Integer = Val(DataGridView1.CurrentRow.Index.ToString) If (r1.Checked) Then WebBrowser1.Url = New Uri(DataGridView1.Rows(cur).Cells(2).Value) Else WebBrowser1.Url = New Uri(DataGridView1.Rows(cur).Cells(1).Value) End If Catch ex As Exception End Try
End Sub
Private Sub Button1_Click( ...
    Dim ibox As String = InputBox("Press OK for default or type your href" & _ Chr(10) & "Sample is " & Chr(10) & "+ http://www.thaiall.com" & Chr(10) & _ "+ http://www.thaiall.com/ipic") If (Len(ibox) = 0) Then Dim basehref() As String = Split(TextBox2.Text, "/") TextBox3.Text = "http://" & basehref(2) Else TextBox3.Text = ibox End If Dim fn As FileStream = New FileStream(htmlfile, FileMode.Create, FileAccess.Write) Dim req As WebRequest = WebRequest.Create(TextBox2.Text) Dim resp As WebResponse = req.GetResponse() Dim webstream As Stream = resp.GetResponseStream() Dim data(1000) As Byte Dim dataLen As Integer Do dataLen = webstream.Read(data, 0, 1000) If dataLen = 0 Then Exit Do fn.Write(data, 0, dataLen) Loop resp.Close() fn.Close() fn = New FileStream(htmlfile, FileMode.Open) Dim fw As FileStream Dim sr As StreamReader = New StreamReader(fn, Encoding.Default) Dim i As Integer = 0 Dim a(), b(), c() As String Dim o, localfile, lastname As String Dim tag As New Collection() Do While sr.Peek() >= 0 o = Replace(sr.ReadLine, Chr(34), "") ' " o = Replace(o, Chr(39), "") ' ' o = Replace(o, "../", "") o = Replace(o, "./", "") If (r1.Checked) Then a = Split(o, "<img src=") Else a = Split(o, "<a href=") End If If (a.Length > 1) Then b = Split(a(1), ">") If (b(0).Length > 5) Then c = Split(b(0), " ") If (Mid(c(0), 1, 4)) <> "http" Then c(0) = TextBox3.Text & "/" & c(0) End If Try lastname = Split(c(0), ".")(Split(c(0), ".").Length - 1) If (Len(lastname) > 4) Then Exit Try i = i + 1 localfile = "c:\" & TextBox4.Text & i & "." & lastname If (r1.Checked) Then tag.Add(c(0) & "," & localfile, c(0)) Else tag.Add(c(0), c(0)) Exit Try End If fw = New FileStream(localfile, FileMode.Create, FileAccess.Write) req = WebRequest.Create(c(0)) resp = req.GetResponse() webstream = resp.GetResponseStream() Do dataLen = webstream.Read(data, 0, 1000) If dataLen = 0 Then Exit Do fw.Write(data, 0, dataLen) Loop resp.Close() fw.Close() Catch ex As Exception End Try End If End If Loop fn.Close() For Each t As Object In tag i = DataGridView1.Rows.Count() DataGridView1.Rows.Add() DataGridView1.Rows(i).Cells(0).Value = i + 1 DataGridView1.Rows(i).Cells(1).Value = Split(t, ",")(0) If (r1.Checked) Then DataGridView1.Rows(i).Cells(2).Value = Split(t, ",")(1) Next t
End Sub
End Class

http://goo.gl/72BPC