Link to home
Start Free TrialLog in
Avatar of beebop
beebop

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

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
Avatar of beebop
beebop

ASKER

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.
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!

Avatar of beebop

ASKER

thankyou mcrider, works perfectly
cheers
bee
Thanks for the points! Glad I could help!


Cheers!
Avatar of beebop

ASKER

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.
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!