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 = "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:\Test\Web Pages\" ;<--- 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 objectclose(ImageList) ; now get any CSS files that are linked to the document ; and add them into the URL and local lists so they can be downloaded... CSSList = browserdoc.GetElementsBytagName("LINK") for x = 0 to CSSList.length-1 thislink = CSSLink.item(x) if strindexNC(thislink.src ".css", 1, @fwdscan) ImageURLList = ItemInsert(thislink.src, -1, ImageURLList, @LF) thisCSS = ItemExtract(ItemCount(thislink.src, "/"), thislink.src, "/") ImageLocalList = ItemInsert(thisCSS, -1, ImageLocalList, @LF) thislink.src = strcat(imageFolder, "\", thisCSS) endif objectclose(thislink) next objectclose(CSSList) ; now loop thru all the objects on the page and pull out the backgrounds ; in any tables or table cells, and add them to the download lists... for x = 0 to all.length-1 thisitem = all.item(x) if thisitem.tagname == "TABLE" || thisitem.tagname == "TD" bg = thisitem.background if bg <> "" ImageURLList = ItemInsert(thisitem.background, -1, ImageURLList, @LF) thisBG = ItemExtract(ItemCount(thisitem.background, "/"), thisitem.background, "/") ImageLocalList = ItemInsert(thisBG, -1, ImageLocalList, @LF) thisitem.background = strcat(imageFolder, "\", thisBG) endif endif objectclose(thisitem) next ; find all the scripts on the page and get their SRC property so they can be downloaded... ScriptList = browserdoc.GetElementsBytagName("SCRIPT") for x = 0 to ScriptList.length-1 thisscript = ScriptList.item(x) if thisscript.src <> "" ImageURLList = ItemInsert(thisscript.src, -1, ImageURLList, @LF) thisSRC = ItemExtract(ItemCount(thisscript.src, "/"), thisscript.src, "/") ImageLocalList = ItemInsert(thisSRC, -1, ImageLocalList, @LF) thisscript.src = strcat(imageFolder, "\", thisSRC) endif objectclose(thisscript) next objectclose(ScriptList) ;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 to return to the page at a later date... bodytxt = StrCat("", @CRLF, "", @CRLF, bodytxt, @CRLF, "") ; ; write the new HTML to the file... FilePut(filename, bodytxt) ; ; close up the browser objects br.quit objectclose(body) objectclose(all) objectclose(browserdoc) objectclose(browser) ; Message("Debug", "All Done") ; gosub ShowOle ; Return Exit :OpenWinInetSession AddExtender("WWINT34i.DLL") tophandle=iBegin(0,"","") Return :CloseWinInetSession iClose(tophandle) Return :DownLoadIMG datahandle=iUrlOpen(tophandle, thisSRC) xx=iReadData(datahandle, downloadFilename) iClose(datahandle) Return :ShowOLE vars = intcontrol(77, 12, 0, 0, 0) olelist = "" for x = 1 to itemcount(vars, @tab) thisvar = itemextract(x, vars, @tab) if vartype(%thisvar%) == 17 then olelist = iteminsert(thisvar, -1, olelist, @lf) next if olelist <> "" then message("Debug", olelist) return
Article ID: W16113
File Created: 2004:08:02:11:19:58
Last Updated: 2004:08:02:11:19:58