1

I would like to download only the HTML code in my VB6 program. Webbrowser control is good but it hangs and also it has issues such as needing to disable the JavaScript, pic, etc in order to get just the HTML

The Inet control is better, but it is "buggy"

Is there any other control ?

Deanna
  • 23,876
  • 7
  • 71
  • 156
Nok Imchen
  • 2,802
  • 7
  • 33
  • 59
  • possible duplicate of [Download File - VB6](http://stackoverflow.com/questions/1976152/download-file-vb6) – MarkJ Dec 26 '11 at 21:18

4 Answers4

4

If you only want to download the HTML of a page, you can easily use Winsock control.

Private Sub Form_Load()
  Winsock1.Connect "stackoverflow.com", 80
End Sub

Private Sub Winsock1_Close()
  Winsock1.Close
End Sub

Private Sub Winsock1_Connect()
  Winsock1.SendData "GET /questions/8624871/vb6-alternative-to-inet-webbrowser-control HTTP/1.1" & vbCrLf & "Host: stackoverflow.com" & vbCrLf & vbCrLf
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  Dim s As String

  Winsock1.GetData s, vbString
  RichTextBox1.Text = RichTextBox1.Text & s
End Sub
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • Hrm, this is a better solution. I should have actually read the question... +1 – Cody Gray - on strike Dec 24 '11 at 15:18
  • How to knw how much percent the page is downloaded?? – Nok Imchen Dec 24 '11 at 15:32
  • 1
    @NokImchen There should be `Content-Length: XXXXX` in the header, to which you can compare the accumulated values of `bytesTotal`. If there's no `Content-Length` in the header, then you only know it's done when the connection is closed. – GSerg Dec 24 '11 at 15:43
  • The Inet control isn't really buggy but it does have its quirks. Better than rolling your own HTTP though you might consider the various HTTP requests that are already in Windows (WinHTTP, XMLHTTP, etc.). – Bob77 Dec 26 '11 at 18:36
3

My suggestion is to host WebKit.NET in your VB 6 application just like you would any other .NET control.

Although it is a .NET control, which means that it won't work natively out-of-the-box with VB 6, it is possible to use controls developed in .NET with a VB 6 application. Microsoft provides the Interop Forms Toolkit as an interoperability mechanism between the two languages.

Essentially, you'll use one of the .NET languages (it doesn't have to be VB.NET; you could also use C#) to create an ActiveX DLL containing your UserControl and register it for COM interop. Then, you can add this ActiveX control to your VB 6 project and hook up to handle the events it raises.

You can find a more complete sample on how to do this here on CodeProject, or here on CodeGuru.

Indeed this approach is not going to be trivial to implement. But I suspect that it's your only alternative to the bundled WebBrowser control, considering that IE was pretty much dominating the browser market back when VB 6 was popular and no one is developing new controls for VB 6 anymore.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • Looking back on this, I see that I misinterpreted the question (in my defense, it was edited; [the original](http://stackoverflow.com/revisions/8624871/1) was less than clear). Some of the other solutions are *much* better for this specific task. However, I won't delete my answer, as it may be useful to others who hit other limitations of the built-in WebBrowser control. – Cody Gray - on strike May 20 '14 at 07:33
  • yes I'm glad you didn't delete your solution as it answers one I have. I have found a lot of your answers very helpful down the years, thanks. – kjack Sep 28 '17 at 07:00
2

You don't need API calls, you don't need WinSock, you don't need Inet, you don't need WebKit interop. Just do it the easy way, using native VB6 code. Here's an excellent article by Karl Peterson with sample code.

MarkJ
  • 30,070
  • 5
  • 68
  • 111
1

This is good code, and it works even in ASP, VBScript.

Function GetHTMLCode(strURL) As String
    Dim strReturn                   ' As String
    Dim objHTTP                     ' As MSXML.XMLHTTPRequest
    If Len(strURL)=0 Then EXIT FUNCTION
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    objHTTP.open "GET", strURL,False
    objHTTP.send                    'Get it.
    strReturn =objHTTP.responseText
    Set objHTTP = Nothing 
    GetHTMLCode = strReturn 
End Function

Now call this function like this (always write with protocol):

Msgbox GetHTMLCode("http://www.stackoverflow.com")
Searush
  • 628
  • 1
  • 5
  • 18