'//转换中文为unicode function URLEncoding(vstrIn) dim i dim strReturn,ThisChr,innerCode,Hight8,Low8 strReturn = "" for i = 1 to Len(vstrIn) ThisChr = Mid(vStrIn,i,1) If Abs(Asc(ThisChr)) < &HFF then strReturn = strReturn & ThisChr else innerCode = Asc(ThisChr) If innerCode < 0 then innerCode = innerCode + &H10000 end If Hight8 = (innerCode and &HFF00)\ &HFF Low8 = innerCode and &HFF strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8) end If next URLEncoding = strReturnend function'//转换unicode到正常文本 function bytes2BSTR(vIn) dim i dim strReturn,ThisCharCode,nextCharCode strReturn = "" for i = 1 to LenB(vIn) ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode < &H80 then strReturn = strReturn & Chr(ThisCharCode) else nextCharCode = AscB(MidB(vIn,i+1,1)) strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(nextCharCode)) i = i + 1 end If next bytes2BSTR = strReturnend functionfunction getText(url) dim oReq
on error resume next '//创建XMLHTTP对象 set oReq = CreateObject("MSXML2.XMLHTTP") oReq.open "get",url,false oReq.send
if oReq.status = 200 then getText = bytes2BSTR(oReq.responseBody) else getText = "" end ifend function
adodb.stream转换法。<% ’常用函数 ’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,"GB2312") set http=nothing if err.number<>0 then err.Clear end function Function BytesToBstr(body) 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 = "GB2312" ’转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP组件调用有中文字符的网页得到的将是乱码 BytesToBstr = objstream.ReadText objstream.Close set objstream = nothing End Function ’下面试着调用http://www.3doing.com/earticle/的html内容 Dim Url,Html Url="http://www.3doing.com/earticle/"; Html = getHTTPPage(Url) Response.write Html %>
其他的没条件测试,哈,揣摩一下吧
function URLEncoding(vstrIn) dim i
dim strReturn,ThisChr,innerCode,Hight8,Low8 strReturn = ""
for i = 1 to Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF then
strReturn = strReturn & ThisChr
else
innerCode = Asc(ThisChr)
If innerCode < 0 then
innerCode = innerCode + &H10000
end If
Hight8 = (innerCode and &HFF00)\ &HFF
Low8 = innerCode and &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
end If
next URLEncoding = strReturnend function'//转换unicode到正常文本
function bytes2BSTR(vIn)
dim i
dim strReturn,ThisCharCode,nextCharCode strReturn = ""
for i = 1 to LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 then
strReturn = strReturn & Chr(ThisCharCode)
else
nextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(nextCharCode))
i = i + 1
end If
next
bytes2BSTR = strReturnend functionfunction getText(url) dim oReq
on error resume next '//创建XMLHTTP对象
set oReq = CreateObject("MSXML2.XMLHTTP") oReq.open "get",url,false
oReq.send
if oReq.status = 200 then
getText = bytes2BSTR(oReq.responseBody)
else
getText = ""
end ifend function
’常用函数
’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,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function
Function BytesToBstr(body)
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 = "GB2312" ’转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP组件调用有中文字符的网页得到的将是乱码
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
’下面试着调用http://www.3doing.com/earticle/的html内容
Dim Url,Html
Url="http://www.3doing.com/earticle/";
Html = getHTTPPage(Url)
Response.write Html
%>