get html

I want to get the source code of a web page. I have tried
Dim bFile() As Byte         ' Retrieving a binary file.

bFile() = Inet1.OpenURL _
    ("http://www.webpage.htm", _
    icByteArray)

' Write file to disk.
Open "C:\web\main.htm" For Binary Access Write As #1
Put #1, , bFile()
Close #1

I have also tried opening the webpage in a richtextbox and saving as a file.
The problem is I want the file that I save to be exactly the same, line for line as the document Im downloading. Doing it both of these ways the file I get back is a mass of text on the first few lines. Adter I get the file I want to be able to go through it line by line.
I hope this is clear enough
beebopAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mcriderConnect With a Mentor Commented:
Try this instead:

Dim lPage As String

lPage = Inet1.OpenURL("http://www.webpage.com", icString)
Do While Inet1.StillExecuting = True
    DoEvents
Loop
Open "C:\web\main.htm" For Output Access Write As #1
Put #1, , lPage
Close #1


Cheers!
0
 
beebopAuthor Commented:
It is producing an error 'bad file number'
Dim lPage As String
fnum5 = FreeFile()
lPage = Inet1.OpenURL("http://www.webpage.com", icString)
Do While Inet1.StillExecuting = True
    DoEvents
Loop
Open myfile For Output Access Write As #fnum5
Put #fnum5, , lPage
Close #fnum5

works with print instead of put, but still the same problem, All the text on the first few lines.
0
 
mcriderCommented:
Sorry, your're right, that should have been print, not put... I just copied your example and changed the OpenURL line.

Try this:

Dim iVal As Long
Dim lPage As String

lPage = Inet1.OpenURL("http://www.webpage.com", icString)
Do While Inet1.StillExecuting = True
    DoEvents
Loop
Open "C:\web\main.htm" For Output Access Write As #1
Do
    iVal = InStr(1, lPage, Chr$(10))
    If iVal = 0 Then Exit Do
    Print #1, Left$(lPage, iVal - 1)
    lPage = Mid$(lPage, iVal + 1)
Loop
Print #1, lPage
Close #1


Cheers!

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
beebopAuthor Commented:
thankyou mcrider, works perfectly
cheers
bee
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
 
beebopAuthor Commented:
just one more bit of advice, if you know. Does the inet control have a limit on the size of file it will download, and if so can it be changed. I am trying to download a 75kb file and it cuts off half way through.
0
 
mcriderCommented:
There is no limit.  Check out these microsoft documents:

FIX: INET OpenURL Method Doesn't Download Complete Files
http://support.microsoft.com/support/kb/articles/Q171/8/28.asp?LNG=ENG&SA=MSDN 
 
INFO: Visual Basic 5.0 Fixes in Visual Studio 97 Service Pack 2
http://support.microsoft.com/support/kb/articles/Q171/5/54.asp?LNG=ENG&SA=MSDN 
 
Since this is extra information, if you're feeling generous, you can open a new question here with the title "FOR MCRIDER ONLY" and assign a couple of points to it... I will answer it.



Cheers!
0
All Courses

From novice to tech pro — start learning today.