Hi,
I've been working on a project that will help me save some time. It
basically reads a URL and saves it to disk as an html file. In other
words, I just wanted to make the automated version of "Save As -> HTML
Only" command on Internet Explorer.
I use XMLHTTP component for this task. I created 3 functions:
readURL: Reads the given URL using Microsoft.XMLHTTP component and
returns the content.
createHTMLFile: Creates the HTML file using the given body string. It
was giving me error before I use the getFileFormat.
getFileFormat: I copied and pasted from a newsgroup, supposed to find
the content format (ASCII or UNICODE)
Here is my catastrophe: If I don't use getFileFormat, XMLHTTP output
cannot be saved. If I use the getFileFormat, it saves in UNICODE and I
cannot use the file in other text processing tools, such as Handy File
Find & Replace. I also doublechecked the web page I'm saving, it's
using ISO-8859-1 in HTTP headers.
Do you have any suggestions?
Thanks in advance,
~D
function readUrl(url)
Dim xml, search_result, output
' Set xml = Server.CreateObject("Msxml2.XMLHTTP.4.0")
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", url, False
xml.Send
readUrl = xml.responseText
Set xml = Nothing
end function
sub createHTMLFile(file,content)
dim fso, newFile
Set fso = CreateObject("Scripting.FileSystemObject")
'on error resume next
Set newFile = fso.CreateTextFile(file,true,getFileFormat(content ))
'if err > 0 then response.write file
'on error goto 0
newFile.write (content)
newFile.close
set newFile = nothing
set fso = nothing
end sub
function getFileFormat(ByRef vTxt)
const UNICODE = -1, ASCII = 0
a2 = Asc(Mid(vTxt,2,1))
w3 = AscB(MidB(vTxt,3,1))
w2 = AscB(MidB(vTxt,2,1))
getFileFormat = ASCII
if a2<>w2 AND a2=w3 Then getFileFormat = UNICODE
end function