Home All Groups Group Topic Archive Search About

webbrowser object html code

Author
12 May 2005 4:58 AM
Tommy
I use webbrowser to browse a web page and I want to save it to file
automatically. I use 2 methods but not good and failed. Please advise.
Thanks.

(1)
WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER, "c:\abc.htm",
""
WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER, "",
"c:\abc.htm"
WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER, "c:\abc.htm",
"c:\abc.htm"

I tried above 3 method to save.
I don't know whethe it is correct method to identify the saving path but
failed.


(2)
            Set fs = CreateObject("Scripting.FileSystemObject")
            Set filePtr = fs.CreateTextFile("c:\index.html", True)

            filePtr.WriteLine (webbrowser.Document.body.outerHTML)     Or
            filePtr.WriteLine
(webbrowser.Document.documentElement.outerHTML)   Or
            filePtr.WriteLine (webbrowser.Document.All(0).outerHTML)

            filePtr.Close

I tried 3 different methods to retrieve the code
"webbrowser.Document.body.outerHTML",
"webbrowser.Document.documentElement.outerHTML",
"webbrowser.Document.All(0).outerHTML". But I found that 3 method also
changes the original html tag.

Please advise for the above problems. Thanks.

Author
12 May 2005 9:00 PM
mr_unreliable
hi Tommy,

If you want to specify a filename, maybe you should use SAVEAS.

Here is a link that may be of some help (although you will have to
read through a lot of disrespectful comments about Microsoft).

http://www.codecomments.com/archive299-2004-4-186350.html

Also, if you only want the TEXT, you can use Microsoft's xmlHTTP
object.  This is script code, but I trust you will be able to
convert it to vb:

Dim xmlHTTP : Set xmlHTTP = CreateObject("Microsoft.XMLHTTP")
Const sSource = "http://www.dilbert.com"
Const bGetAsAsync = False  ' wait for response

   ' formulate a request to get the Dilbert website...
   xmlHTTP.Open "GET", sSource, bGetAsAsync
   xmlHTTP.Send  ' send it (to the web, wait for result)

   sHTMLPage = xmlHTTP.responseText  ' (note: as TEXT)

At this point, the string sHTMLPage contains the page html.

If you want the other stuff, (graphics, etc) using this method
you will have to go get that too.

For example, to rip the dilbert strip of the day, you have to
parse the html, find the reference (url) to the graphic, and \
then go get that too.

   ' formulate a request to get the image (i.e., the cartoon strip)...
   xmlHTTP.Open "GET", sImageSource, bGetAsAsync
   xmlHTTP.Send  ' send it (to the web, wait for result)

Finally, here is an example of using Microsoft's adoStream object
to save the file to disk (as an alternative to scripting.fso).

Dim adoStream : Set adoStream = CreateObject("adodb.stream")

Const adTypeBinary = 1  ' ado typelib constants
Const adModeReadWrite = 3
Const adSaveCreateOverwrite = 2

   With adoStream  ' setup and write the graphics file to local disk...
     .Type = adTypeBinary  ' as BINARY
     .Mode = adModeReadWrite
     .Open  ' the stream
     .Write xmlHTTP.responseBody  ' write the data (as binary)...
     .SaveToFile sSavePath & sSaveName, adSaveCreateOverwrite
     .Close  ' the stream
   End With

cheers, jw


Tommy wrote:
Show quote
> I use webbrowser to browse a web page and I want to save it to file
> automatically. I use 2 methods but not good and failed. Please advise.
> Thanks.
>
> (1)
> WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER, "c:\abc.htm",
> ""
> WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER, "",
> "c:\abc.htm"
> WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER, "c:\abc.htm",
> "c:\abc.htm"
>
> I tried above 3 method to save.
> I don't know whethe it is correct method to identify the saving path but
> failed.
>
>
> (2)
>             Set fs = CreateObject("Scripting.FileSystemObject")
>             Set filePtr = fs.CreateTextFile("c:\index.html", True)
>
>             filePtr.WriteLine (webbrowser.Document.body.outerHTML)     Or
>             filePtr.WriteLine
> (webbrowser.Document.documentElement.outerHTML)   Or
>             filePtr.WriteLine (webbrowser.Document.All(0).outerHTML)
>
>             filePtr.Close
>
> I tried 3 different methods to retrieve the code
> "webbrowser.Document.body.outerHTML",
> "webbrowser.Document.documentElement.outerHTML",
> "webbrowser.Document.All(0).outerHTML". But I found that 3 method also
> changes the original html tag.
>
> Please advise for the above problems. Thanks.
>
>
>
Author
13 May 2005 3:03 AM
Tommy
thx very much

"mr_unreliable" <kindlyReplyToNewsgr***@notmail.com>
???????:ei24ERzVFHA.3***@TK2MSFTNGP10.phx.gbl...
Show quote
> hi Tommy,
>
> If you want to specify a filename, maybe you should use SAVEAS.
>
> Here is a link that may be of some help (although you will have to
> read through a lot of disrespectful comments about Microsoft).
>
> http://www.codecomments.com/archive299-2004-4-186350.html
>
> Also, if you only want the TEXT, you can use Microsoft's xmlHTTP
> object.  This is script code, but I trust you will be able to
> convert it to vb:
>
> Dim xmlHTTP : Set xmlHTTP = CreateObject("Microsoft.XMLHTTP")
> Const sSource = "http://www.dilbert.com"
> Const bGetAsAsync = False  ' wait for response
>
>   ' formulate a request to get the Dilbert website...
>   xmlHTTP.Open "GET", sSource, bGetAsAsync
>   xmlHTTP.Send  ' send it (to the web, wait for result)
>
>   sHTMLPage = xmlHTTP.responseText  ' (note: as TEXT)
>
> At this point, the string sHTMLPage contains the page html.
>
> If you want the other stuff, (graphics, etc) using this method
> you will have to go get that too.
>
> For example, to rip the dilbert strip of the day, you have to
> parse the html, find the reference (url) to the graphic, and \
> then go get that too.
>
>   ' formulate a request to get the image (i.e., the cartoon strip)...
>   xmlHTTP.Open "GET", sImageSource, bGetAsAsync
>   xmlHTTP.Send  ' send it (to the web, wait for result)
>
> Finally, here is an example of using Microsoft's adoStream object
> to save the file to disk (as an alternative to scripting.fso).
>
> Dim adoStream : Set adoStream = CreateObject("adodb.stream")
>
> Const adTypeBinary = 1  ' ado typelib constants
> Const adModeReadWrite = 3
> Const adSaveCreateOverwrite = 2
>
>   With adoStream  ' setup and write the graphics file to local disk...
>     .Type = adTypeBinary  ' as BINARY
>     .Mode = adModeReadWrite
>     .Open  ' the stream
>     .Write xmlHTTP.responseBody  ' write the data (as binary)...
>     .SaveToFile sSavePath & sSaveName, adSaveCreateOverwrite
>     .Close  ' the stream
>   End With
>
> cheers, jw
>
>
> Tommy wrote:
>> I use webbrowser to browse a web page and I want to save it to file
>> automatically. I use 2 methods but not good and failed. Please advise.
>> Thanks.
>>
>> (1)
>> WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER,
>> "c:\abc.htm", ""
>> WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER, "",
>> "c:\abc.htm"
>> WebBrowser.ExecWB OLECMDID_SAVE, OLECMDEXECOPT_DONTPROMPTUSER,
>> "c:\abc.htm", "c:\abc.htm"
>>
>> I tried above 3 method to save.
>> I don't know whethe it is correct method to identify the saving path but
>> failed.
>>
>>
>> (2)
>>             Set fs = CreateObject("Scripting.FileSystemObject")
>>             Set filePtr = fs.CreateTextFile("c:\index.html", True)
>>
>>             filePtr.WriteLine (webbrowser.Document.body.outerHTML)     Or
>>             filePtr.WriteLine
>> (webbrowser.Document.documentElement.outerHTML)   Or
>>             filePtr.WriteLine (webbrowser.Document.All(0).outerHTML)
>>
>>             filePtr.Close
>>
>> I tried 3 different methods to retrieve the code
>> "webbrowser.Document.body.outerHTML",
>> "webbrowser.Document.documentElement.outerHTML",
>> "webbrowser.Document.All(0).outerHTML". But I found that 3 method also
>> changes the original html tag.
>>
>> Please advise for the above problems. Thanks.
>>
>>

AddThis Social Bookmark Button