由于js不能跨域,所以获取只能在本地成功,服务器上不会成功。
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>test</title>
</head>
<body>
关于百度页面http://ir.baidu.com/phoenix.zhtml?c=188488&p=irol-homeprofile源码内容如下:<br/>
<divid="t1"></div>
<scripttype="text/javascript">
functioncreateXmlHttpRequest()
{
try{returnnewXMLHttpRequest();}
catch(e)
{
returnnewActiveXObject("Microsoft.XMLHTTP");}
}
varxmlHttp=createXmlHttpRequest();
xmlHttp.open("get","http://ir.baidu.com/phoenix.zhtml?c=188488&p=irol-homeprofile",false);
xmlHttp.send();
if(xmlHttp.readyState==4&&xmlHttp.status==200)
{
str=xmlHttp.responseText;//str即为返回的html内容
varstr1=newRegExp(">","g");
varstr2=newRegExp("<","g");
varstr3=newRegExp("\r","g");
str=str.replace(str2,"<");
str=str.replace(str1,">");
str=str.replace(str3,"<br/>");
document.getElementById("t1").innerHTML=str;
}
</script>
</body>
</html>