asp生成html(utf-8)
<%'常用函数'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码functiongetHTTPPage(url)dimHttpsetHtt...
<%
'常用函数
'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"utf-8")
set http=nothing
if err.number<>0 then err.Clear
end function
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
txtURL=CStr(Request.ServerVariables("SCRIPT_NAME"))
n=InStrRev(txtURL,"/") '从右边第一个字符起查找"_"的位置,n为返回值
txtURL=left(txtURL, n)'显示从左边数第"n"个字符前面的字符,
txtURL="http://"&Request.ServerVariables("SERVER_NAME")&""&txtURL&"index.asp"
sText = getHTTPPage(txtURL)
sText=replace(sText,"www.html","../../www.html")
filename=server.MapPath("index.html")
Function WriteToFile (FileUrl, Str, CharSet)
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.WriteText Str
stm.SaveToFile FileUrl, 2
stm.flush
stm.Close
Set stm = Nothing
End Function
WriteToFile filename,sText,"utf-8"
%>
为什么上面的代码生成不了utf-8的html?
sText = getHTTPPage(txtURL)
sText=replace(sText,"www.html","../../www.html")
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename="index.htm"
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
%>
替换上面生成和写入的代码。,能生成GB2312静态页面
谁能帮我指点下,或者给个生成静态UTF-8的案例 展开
'常用函数
'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"utf-8")
set http=nothing
if err.number<>0 then err.Clear
end function
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
txtURL=CStr(Request.ServerVariables("SCRIPT_NAME"))
n=InStrRev(txtURL,"/") '从右边第一个字符起查找"_"的位置,n为返回值
txtURL=left(txtURL, n)'显示从左边数第"n"个字符前面的字符,
txtURL="http://"&Request.ServerVariables("SERVER_NAME")&""&txtURL&"index.asp"
sText = getHTTPPage(txtURL)
sText=replace(sText,"www.html","../../www.html")
filename=server.MapPath("index.html")
Function WriteToFile (FileUrl, Str, CharSet)
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.WriteText Str
stm.SaveToFile FileUrl, 2
stm.flush
stm.Close
Set stm = Nothing
End Function
WriteToFile filename,sText,"utf-8"
%>
为什么上面的代码生成不了utf-8的html?
sText = getHTTPPage(txtURL)
sText=replace(sText,"www.html","../../www.html")
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename="index.htm"
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
%>
替换上面生成和写入的代码。,能生成GB2312静态页面
谁能帮我指点下,或者给个生成静态UTF-8的案例 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询