• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

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.
0
VBNewbie
Asked:
VBNewbie
  • 5
  • 3
  • 2
  • +1
1 Solution
 
ATMCommented:
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
'------------------------------------------------------------

0
 
VBNewbieAuthor Commented:
ATM
How would you activate the code. Is there a commnad button? I was not successful running your code. Thnanks again
0
 
VBNewbieAuthor Commented:
ATM
Do I need to add a command button?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gabesterCommented:
ATM,

I don't mean to reject your answer. I didn't know how to unlock the question.
0
 
gabesterCommented:
VBNewbie
0
 
VBNewbieAuthor Commented:
How can I unreject ATMs answer?
0
 
VBNewbieAuthor Commented:
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.
0
 
AzraSoundCommented:
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
0
 
ATMCommented:
If You starts new project, open Add winsock control and add events as shown. ActionStartup is Your Command_OnClick event, change editbox names as need.
0
 
ATMCommented:
+, 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.
0
 
VBNewbieAuthor Commented:
Thanks ATM. I really appreciate the help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now