Link to home
Start Free TrialLog in
Avatar of VBNewbie
VBNewbie

asked on

Web Browser

I would like create a web browser that will strip out all graphics. It will basically just show all text, much like Lynxx Browser for Unix. I need to connect to a proxy server.
Avatar of ATM
ATM

You can use this code to retrieve HTML source. When You directly use winsock, its potentially too much faster than if use other components.

Public JobURL As String
Public ResponseDocument As String
Public StepCount As Long
Public IsProxyUsed As Boolean
Public ServerHostIP As String
Public ServerPort As Long

'------------------------------------------------------------

Dim LocalStepCounter As Long
Dim RequestHeader As String
Dim RequestTemplate As String
'------------------------------------------------------------

Public Sub ActionStartup()
   
  If UCase(Left(JobURL, 7)) <> "HTTP://" Then
     MsgBox "Please enter url with http://", vbCritical + vbOK
     FrmActionWait.Hide
     Unload FrmActionWait
     Exit Sub
  End If
   
  LocalStepCounter = 0
  RequestHeader = ""
  RequestTemplate = "GET _$-$_$- HTTP/1.0" & Chr(13) & Chr(10) & _
                "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-comet, */*" & Chr(13) & Chr(10) & _
                "Accept-Language: en" & Chr(13) & Chr(10) & _
                "Accept-Encoding: gzip , deflate" & Chr(13) & Chr(10) & _
                "Cache-Control: no-cache" & Chr(13) & Chr(10) & _
                "Proxy-Connection: Keep-Alive" & Chr(13) & Chr(10) & _
                "User-Agent: SSM Agent 1.0" & Chr(13) & Chr(10)
   
  pureURL = Right(JobURL, Len(JobURL) - 7)
  startPos = InStr(1, pureURL, "/")
 
  If startPos < 1 Then
     ServerAddress = pureURL
     documentURI = "/"
  Else
     ServerAddress = Left(pureURL, startPos - 1)
     documentURI = Right(pureURL, Len(pureURL) - startPos + 1)
  End If
     
  If ServerAddress = "" Or documentURI = "" Then
     MsgBox "Unable to detect target page!", vbCritical + vbOK
     FrmActionWait.Hide
     Unload FrmActionWait
     Exit Sub
  End If
 
  If IsProxyUsed Then
     
      If ServerHostIP = "" Then
         MsgBox "Unable to detect proxy address!", vbCritical + vbOK
         FrmActionWait.Hide
         Unload FrmActionWait
         Exit Sub
      End If
     
      RequestHeader = RequestTemplate & "Host: @$@@$@" & Chr(13) & Chr(10)
      RequestHeader = Replace(RequestHeader, "@$@@$@", ServerAddress)
      RequestHeader = Replace(RequestHeader, "_$-$_$-", JobURL)
  Else
      ServerHostIP = ServerAddress
      ServerPort = 80
      RequestHeader = RequestTemplate
      RequestHeader = Replace(RequestHeader, "_$-$_$-", documentURI)
  End If
 
  Me.Show
  RequestHeader = RequestHeader & Chr(13) & Chr(10)
  TxtStatus.Text = "Connecting to server ..."
  TxtStatus.Refresh
   
  WS_HTTP.Connect ServerHostIP, ServerPort
End Sub

'------------------------------------------------------------
Private Sub WS_HTTP_Close()
  WS_HTTP.Close
  TxtStatus.Text = "Transaction completed ..."
  TxtStatus.Refresh
  Me.Hide
  Unload Me
End Sub

'------------------------------------------------------------
Private Sub WS_HTTP_Connect()
  WS_HTTP.SendData RequestHeader
  TxtStatus.Text = "Connected, try to obtain page ..."
  TxtStatus.Refresh
  FrmMainWin.TxtResponse.Text = ""
  FrmMainWin.TxtResponse.Refresh
End Sub

'------------------------------------------------------------
Private Sub WS_HTTP_DataArrival(ByVal bytesTotal As Long)
   Dim tmpString As String
   WS_HTTP.GetData tmpString, vbString
   FrmMainWin.TxtResponse.Text = FrmMainWin.TxtResponse.Text & tmpString
   FrmMainWin.TxtResponse.Refresh
   TxtStatus.Text = "Data from server, continue ..."
   TxtStatus.Refresh
End Sub

'------------------------------------------------------------
Private Sub WS_HTTP_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)
  WS_HTTP.Close
  TxtStatus.Text = "Errors occured ..."
  TxtStatus.Refresh
  Me.Hide
  Unload Me
End Sub
'------------------------------------------------------------

Avatar of VBNewbie

ASKER

ATM
How would you activate the code. Is there a commnad button? I was not successful running your code. Thnanks again
ATM
Do I need to add a command button?
ATM,

I don't mean to reject your answer. I didn't know how to unlock the question.
VBNewbie
How can I unreject ATMs answer?
ATM
gabester is my friend and is helping with my program. He is able to write something like what you wrote but he can't seem to strip out the graphics. He has one form that with a few text boxes. He has a text box for the URL and also for the result. He has a couple command button. for exit, retrieve, and clear. I have a feeling that your answer will work, how do i unreject your answer? Sorry for the confusion.
this code shows how to scan an html document and retrieve image tags and their values.  Just adjust it to delete those tags adn reload the page with the tags deleted

http://www.vbsquare.com/tips/tip174.html
ASKER CERTIFIED SOLUTION
Avatar of ATM
ATM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
+, You must set IsProxyUsed to true when use proxy server (its must be Server with no authorization), If you use proxy then set ServerHostIP and ServerPort to proxy server parameters. If no proxies used do nothing with these variables, and set IsProxyUsed to False.
Thanks ATM. I really appreciate the help.