用XML
[CODE]
<script>
findcode(re)
{
}
function ExecuteXmlHttp(url) //下载指定地址源文件
{
var xmlhttp=false;
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}
if(!xmlhttp && typeof XMLHttpRequest!='undefined')
{
xmlhttp = new XMLHttpRequest();
}
xmlhttp.open("get",url,true);
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState==4)
{
source=xmlhttp.responsetext;
document.getElementById("spre").innerHTML=source; //需要自己解码,否则乱码
alert("源文件长度为:" + source.length);
return false;
}
}
xmlhttp.send(null);
}
</script>
<body>
地址:<input type=text id=txtin name=txtin value=http://www.126.com><input type=button value=提交 onclick=ExecuteXmlHttp(document.all("txtin").value)><br>
<hr color=red>
<span id=spre> </span>
</body>
[/CODE]
上面代码只能在本地运行,远程访问无权限,若想在网站上用,应该用这个(asp的)
<%
'常用函数
'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
Dim charset
charset=request("lstset")
if charset="" then charset="GB2312"
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,charset)
set http=nothing
if err.number<>0 then err.Clear
end function
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
Function BytesToBstr(body,charset)
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 = charset '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP组件调用有中文字符的网页得到的将是乱码
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
'下面试着调用网页的html内容
Dim Url,Html,offset,header,footer,res
Url=request("ul")
if Url="" then Url="http://easy66.jx828.net/b.htm"
if Instr(Url,"http://")=0 then Url="http://" & Url
Html = getHTTPPage(Url)
offset=Instr(Lcase(Html),"</title>")+8
header=left(Html,offset-1)
footer=right(Html,len(Html)-offset+1)
Dim urlbase,urloffset
if (InstrRev(Url,"/") > InstrRev(Url,"//")+1) and (InstrRev(Url,".") > InstrRev(Url,"/")) then
urloffset=InStrRev(Url,"/")
urlbase=left(Url,urloffset)
else
urlbase=Url & "/"
end if
res=header & "<base href='" & urlbase & "'>" & footer
%>
[此贴子已经被作者于2006-8-4 8:31:39编辑过]