- Imports System.IO
- Imports System.IO.FileStream
- Imports System.Net
- Imports System.Text
- Imports System.Text.Encoding
- Imports System.Threading
- Imports System.Reflection
Tác giả: Nguyễn Trung Tín
Mô tả: Lấy source 1 trang web
Thấy có cái này http://caulacbovb.com/forum/viewtopic.php?f=20&t=103 của NoBi nhưng bằng C#...
Lúc chạy có thể Form sẽ bị đứng...

Mà chỉ lấy source của những trang có tên hoàn chỉnh ví dụ như http://caulacbovb.com/forum/ .Nếu gõ caulacbovb.com/forum thì có thể sẽ không chạy...

Các control cần có
-TextBox : txtURL
-Button : Button1
-RichTextBox : RichTextBox1
'NameSpace
Mã: Chọn hết
'Code cho sự kiện Button1_Click
Mã: Chọn hết
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim respHTML As String
- Try
- Dim path As String = txtURL.Text
- Dim wReq As WebRequest = WebRequest.Create(path)
- If TypeOf wReq Is HttpWebRequest Then
- CType(wReq, HttpWebRequest).UserAgent = "VB.NET Lấy Source trang Web"
- End If
- Dim wResp As WebResponse = wReq.GetResponse()
- Dim respStream As Stream = wResp.GetResponseStream()
- Dim reader As StreamReader = New StreamReader(respStream, Encoding.Default)
- respHTML = reader.ReadToEnd()
- Catch ex As Exception
- respHTML = "<HTML></HTML>"
- End Try
- 'Ghi source vào RichTextBox
- RichTextBox1.Text = respHTML
-
- End Sub