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:
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.
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.
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.
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.
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!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.