Link to home
Start Free TrialLog in
Avatar of felix07
felix07

asked on

URL call

I want to write a program which asks for a URL, then reads the received page, and saves it on my local disk.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of magglass1
magglass1

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 Richie_Simonetti
Add an Internet transfer control

sub SaveHTML()
dim i as integer

i=freefile
open "c:myfile.htm" for output as #i
    print #i,inet1.openurl("http://www.mysite.com/indextml",icString)
close#i
end sub
If you don't want to use a control, you can use this with Richie's solution.....

Private Sub Form_Load()
GetHTMLCode ("http://www.google.com")
End Sub

Public Function GetHTMLCode(URL As String)
    Dim IE
    Set IE = CreateObject("InternetExplorer.Application")
        IE.Navigate URL
        While IE.Busy
            DoEvents
        Wend
            GetHTMLCode = IE.Document.body.innerHTML
    MsgBox GetHTMLCode
End Function
Avatar of magglass1
magglass1

Or if you want to modify the html first:

Add an Internet transfer control

sub SaveHTML()
dim i as integer

i=freefile
myHTML = Inet1.OpenURL("www.something.com")
'make modifications to myHTML
open "c:myfile.htm" for output as #i
   print #i,myHTML,icString)
close#i
end sub

That should be correct...
nah, nah...that's not fair!!, at least change the name of sub or variable or, better, add "\" that it is missing...
GetHTMLCode = IE.Document.body.innerHTML
 to

GetHTMLCode = IE.Document.documentelement.innerHTML

.Body return the html that is beteween <BODY></BODY> tags,
.Documentelement returns ALL, from <HTML> to </HTML>
Cheers
This code should do the whole thing for you.
First add a refernce to Microsoft Internet Controls (in SHDOCVW.DLL) and add these declarations to a form:


Dim IE As SHDocVw.InternetExplorer
Dim myWebPage As String


Then put a commandbutton (Command1) on the form, change its caption to 'Save a Webpage' and add the following code:


Private Sub Command1_Click()

myWebPage = InputBox("Type in the URL of the Webpage you wish to save", "Save a webpage", "http://www.google.com")
If myWebPage = "" Then Exit Sub 'User cancelled

Command1.Enabled = False 'Stop the user from trying to do more than 1 at a time
Command1.Caption = "Working..."

Set IE = New SHDocVw.InternetExplorer
IE.Navigate2 myWebPage
'IE.Visible=True 'Use this is you want to see the webpage

While IE.ReadyState <> READYSTATE_COMPLETE 'Wait until the browser is done
DoEvents
Wend

IE.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER 'Show save dialogue
Command1.Enabled = True
Command1.Caption = "Save a webpage"
End Sub


Hope this helps,
Kindest regards,
Rhaedes
...I meant to add that the advantage of doing it this way is that it takes advantage of the 'Save As' option in Explorer, so you get all the images and other related files, not just the HTML of the document.
Rhaedes
I am currently working on a program to do the equivlant or better of the 'Save As' option in Explorer.  I have asked a few questions at https://www.experts-exchange.com/questions/20532326/Two-Easy-Qs-About-Retreiving-Website-Source-and-Modifying-Strings.html
Avatar of felix07

ASKER

Thanks a lot for your answers.

Unfortunately, I am facing a new problem : a login and password is required to access to this URL.

How can I give the login and the password (in my Visual Basic program) to be able to access to this URL.

Thanks in advance,

Regards,

Felix.
Check out http://www.httrack.com/index.php.  There program supports using a login name and password on websites.
Should be http://www.httrack.com/index.php without the period at end, lol.
take a look at www.angelfire.com/realm/vb-shared/index.html under "IE DOM ..." topic.
Hi felix07,
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Richie_Simonetti's comment(s) as an answer.
    *** but set the UserName and Password properties, then set the URL property

felix07, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer