Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I save web page source as local text file?

Status
Not open for further replies.

Radian

Programmer
Jul 16, 2001
1
US
I'd like to save the source of a web page as a local text file...any suggestions? I've tried using an InternetExplorer.Application object but I can't figure out how to view/save the source. Thanks
 
Hey, I'm in the same boat. I worked on it for a few hours last night and haven't really come up with a great solution. One solution is a little bit of a hack using sendkeys....but it does work.

You can have IE automatically display the source by using:

ie.Navigate "view-source:
By prefixing your web address with the "view-source:" IE will automatically bring up the source of that page. Then simply use the SendKeys to navigate the SaveAs.

Using the Internet Explorer object I ran into a stopping point. I think it has to do with the security features of Internet Explorer. It doesn't seem to allow you to automatically save a page to the hard drive. I haven't figured a way around it. But here is where I'm at. Use the ExecWB command to save the page. This brings up the SaveAs dialog. You can have the path and file name entered via the ExecWB function but I cannot figure out how to save.

To see what I mean. Use IE to navigate to the page then:

ie.ExecWB 4,2,"d:\test.html, ""

I've tried everything I could think of. Even "d:\test.html" & Chr(13)" get an error every time. Arrrgh!

If anyone has a suggestion or solution I'd appreciate it.

Dave
 
Hey, I've been fighting this all night, found a solution. You are in luck that this browser window is still open in the background.

You can access the text of the browser object through such constructions as:

brwWebBrowser.Document.body.innerHTML
 
Actually it's good only in case you do not want to save images too ( I mead in folder testfiles ) as you will get using SaveAs dialog box. The problem is to pass it automatically.
 
I love MSDN CDs. MSDN / Platform SDK / Web Services / Web Workshop / DHTML / DHTML References / Methods / Exec Command. I have not tried this and do not know if images are saved.

' false for no interface
' Use \\ to separate multiple folder names.

blnSuccess = Webb.document.ExecCommand("SaveAS", false, "C:\folder\\subfolder\file.???"

execCommand Method

--------------------------------------------------------------------------------

Executes a command on the current document, current selection, or the given range.

Syntax

bSuccess = object.execCommand(sCommand [, bUserInterface] [, vValue])
Parameters

sCommand Required. String that specifies the command to execute. This command can be any of the command identifiers that can be executed in script.
bUserInterface Optional. Boolean that specifies one of the following values: false Default. Does not display a user interface.
true Displays a user interface, if the command supports one.

vValue Optional. Variant that specifies the string, number, or other value to assign. Possible values depend on sCommand .

Return Value

Boolean that returns one of the following values:

true The command was successful.
false The command was not successful.

SaveAs Command

--------------------------------------------------------------------------------

Saves the current Web page to a file.

Scripting Information

Command SaveAs
User interface Optional. This command displays a dialogue box if the bUserInterface argument of execCommand is set to true or omitted. It does not display a dialogue box if the argument is set to false or null and the vValue parameter is present (even if it's null).
execCommand vValue Optional. String that specifies the path and file name of the file to which to save the Web page. When the path contains more than one folder name, separate the folder names with two backward slashes (\\).
Applies to execCommand, queryCommandEnabled, queryCommandIndeterm, queryCommandState, queryCommandSupported, queryCommandValue.



Compare Code (Text)
Generate Sort in VB or VBScript
 
I can't find a link right off, but to summarise, the folks at MSDN have a faq somewhere saying that execCommand's SaveAs intentionally doesn't work for security reasons (apparently the useless behavior is nested three class levels down even). I don't know about VBScript, but VFP won't let you send keys to a system window either. elifu had a working alternative utilising the brwWebBrowser.Document.body.innerHTML though. so Thanks elifu!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top