Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
; Winbatch 2004F, MSIE 6 #DefineSubRoutine startMSIE(url) browser = ObjectOpen("InternetExplorer.Application") browser.addressbar = @FALSE browser.statusbar = @FALSE browser.menubar = @FALSE browser.toolbar = @FALSE browser.visible = @TRUE browser.navigate(url) ; wait until page loads... WaitForPageLoad() ; setup the document object... browserDoc = browser.Document all = browserdoc.all Return(browser) #EndSubRoutine #DefineSubroutine WaitForPageLoad() ; assume Browser While browser.busy || browser.readystate == 1 TimeDelay(0.5) EndWhile While browser.Document.ReadyState != "complete" TimeDelay(0.5) EndWhile return #EndSubroutine ; URL of page you wish to Download... ;url = "C:\Test\Winbatch Main Page.htm" url = "http://www.winbatch.com" ;<--- modify to the page you need... ; start the browser... br = startMSIE(url) ; specify the folder you wish to store the pages in... DownloadFolder = "c:\Writing\Winbatch\DLFolder\" ;<--- modify to your own location... ; ; build a current filename from the .title of the current page... cfname = StrTrim(browserdoc.title) If StrSub(cfname, StrLen(cfname), 1) == "." cfname = StrCat(DownloadFolder, cfname, "html") Else cfname = StrCat(DownloadFolder, cfname, ".html") EndIf ; double check with the user... filename = AskLine("Debug", "SAVE AS FILENAME", cfname) ; ; build an image folder inside the download folder... imageFolder = StrCat(DownloadFolder, "Files for ", FileRoot(filename)) ; make the new folder... DirMake(imageFolder) ; ; build a lists to hold the target and destination files... ImageURLList = "" ImageLocalList = "" ; loop thru the images on the page and grab... ImageList = browserdoc.GetElementsBytagName("IMG") For x = 0 To ImageList.length-1 thisImage = ImageList.item(x) ; the source image... thisSRC = thisImage.SRC ImageURLList = ItemInsert(thisSRC, -1, ImageURLList, @LF) ; only the filename for the destination filename... thisIMG = ItemExtract(ItemCount(thisSRC, "/"), thisSRC, "/") ImageLocalList = ItemInsert(thisIMG, -1, ImageLocalList, @LF) ; change the .SRC property to reflect the location of the downloaded image... thisImage.SRC = StrCat(imageFolder, "\", thisIMG) ObjectClose(thisImage) Next ;message("Debug", strcat(ImageURLList, @crlf, @crlf, ImageLocalList)) ; gosub OpenWinInetSession ; loop thru the Image Source and Image List and build a destination ; path/filename for the image files using WinInet... For x = 1 To ItemCount(ImageURLList, @LF) thisSRC = ItemExtract(x, ImageURLList, @LF) SRCName = ItemExtract(x, ImageLocalList, @LF) downloadFilename = StrCat(imageFolder, "\", SRCName) ; message(thisSRC, downloadFilename) ; gosub DownLoadIMG Next ; gosub CloseWinInetSession ; now grab the HTML from the page... body = browserdoc.body bodytxt = body.outerHTML ; strcat a comment to the top of it, with the URL of the page just in case ; you need it later... bodytxt = StrCat("", @CRLF, bodytxt, "") ; ; write the new HTML to the file... FilePut(filename, bodytxt) ; Message("Debug", "All Done") Return Exit :OpenWinInetSession Return :CloseWinInetSession Return :DownLoadIMG Return
Article ID: W16126
File Created: 2004:08:02:11:22:30
Last Updated: 2004:08:02:11:22:30