Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• Adjust flexgrid cell
• Animation
• Centering form text
• Coffee machine
• Creating fileshares
• Creating shortcuts
• Custom buttons
• Directory browser
• Disable mouse events
• File search by ext
• File transfer
• File watcher
• Formatting flexgrid
• Get Content Type
• Get HTML source
• Get modem port
• HTTP proxy
• ipconfig
• Large file split/merge
• MAPI
• MCI Sound Player
• Menu with images
• MP3 normalizer
• Net Send
• Netstat 2000
• No duplicate entries
• Outlook Address Book
• Set font color
• Shapes
• SOAP test
• Text-to-image
• Text file viewer
• Text find/replace
• UPS component
• View NT groups
• Word template
• Writing DNS control
    • Using DNS control
• Writing SMTP control
    • Sending email
    • Mailing list
• Writing WhoIs control
    • Using WhoIs control
• View HTML source
OISV - Organization of Independent Software Vendors - Contributing Member
VB projects - Get HTML Source

Description: Get HTML source of specified URL, using Winsock control
Minimum requirements: VB5 Pro
Download: source code
Screenshot:
Get HTML Source (8 KB)
Project: Standard EXE
ActiveX Controls/Objects: MSWINSCK.OCX
Controls: cmdGet (CommandButton), txtURL (TextBox), Timer1 (Timer), txtSource (TextBox), Winsock1 (Winsock)
Code:
Dim sURL As String
Dim sHost As String
Dim sPage As String
Dim lPort As Long

Private Sub GetHTMLSource(ByVal sURL As String)
    txtSource = ""
    sHost = Mid(sURL, InStr(sURL, "://") + 3)
    If InStr(sHost, "/") > 0 Then
        sPage = Mid(sHost, InStr(sHost, "/"))
        sHost = Left(sHost, InStr(sHost, "/") - 1)
    Else
        sPage = "/"
    End If
    If InStr(sHost, ":") > 0 Then
        lPort = Mid(sHost, InStr(sHost, ":") + 1)
        sHost = Left(sHost, InStr(sHost, ":") - 1)
    Else
        lPort = 80
    End If
    With Winsock1
        If .State <> sckClosed Then .Close
        .RemoteHost = sHost
        .RemotePort = lPort
        .Connect
    End With
End Sub

Private Sub cmdGet_Click()
    GetHTMLSource txtURL
End Sub

Private Sub Timer1_Timer()
    Winsock1.Close
    txtSource = "Connection timeout"
End Sub

Private Sub Winsock1_Connect()
    Timer1.Enabled = True
    Winsock1.SendData "GET " & sPage & " HTTP/1.0" & Chr(10) & Chr(10)
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Timer1.Enabled = False
    Dim sBuffer As String
    Winsock1.GetData sBuffer
    txtSource = txtSource & sBuffer
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, _
  ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, _
  ByVal HelpContext As Long, CancelDisplay As Boolean)
    Winsock1.Close
    txtSource = "Error " & Number & ": " & Description
End Sub

Copyright © 1996-2010 OstroSoft. All rights reserved. info@ostrosoft.com