我正在尝试使用 Javascript 将任何网页的 html 源代码放在字符串中。请告诉我是否可以做其他事情来解决我的问题。我正在使用从另一篇文章中找到的以下代码
function httpGet(theUrl)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
我在 IE Firefox 和 Chrome 中试过这个,但我总是得到以下源代码,它是“PAGE NOT FOUND”页面的源代码。如果你有任何其他信息,请在评论中告诉我。我想要的是从任何网页(如 google.com 和其他网页)获取 html。如果我不能这样做,那我该怎么办?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>404 - PAGE NOT FOUND</title>
<style type="text/css">
body{padding:0;margin:0;font-family:helvetica;}
#container{margin:20px auto;width:868px;}
#container #top404{background-image:url('http://74.53.143.237/images/404top.gif');background-repeat:no-repeat;width:868px;height:168px;}
#container #mid404{background-image:url('http://74.53.143.237/images/404mid.gif');background-repeat:repeat-y;width:868px;}
#container #mid404 #gatorbottom{position:relative;left:39px;float:left;}
#container #mid404 #xxx{float:left;padding:40px 237px 10px;}
#container #mid404 #content{float:left;text-align:center;width:868px;}
#container #mid404 #content #errorcode{font-size:30px;font-weight:800;}
#container #mid404 #content p{font-weight:800;}
#container #mid404 #content #banner{margin:20px 0 0 ;}
#container #mid404 #content #hostedby{font-weight:800;font-size:25px;font-style:italic;margin:20px 0 0;}
#container #mid404 #content #coupon{color:#AB0000;font-size:22px;font-style:italic;}
#container #mid404 #content #getstarted a{color:#AB0000;font-size:31px;font-style:italic;font-weight:800;}
#container #mid404 #content #getstarted {margin:0 0 35px;}
#container #bottom404{background-image:url('http://74.53.143.237/images/404bottom.gif');background-repeat:no-repeat;width:868px;height:14px;}
</style>
</head>
<body>
<div id="container">
<div id="top404"></div>
<div id="mid404">
<div id="gatorbottom"><img src="http://74.53.143.237/images/gatorbottom.png" alt="" /></div>
<div id="xxx"><img src="http://74.53.143.237/images/x.png" alt="" /></div>
<div id="content">
<div id="errorcode">ERROR 404 - PAGE NOT FOUND</div>
<p>Oops! Looks like the page you're looking for was moved or never existed.<br />Make sure you typed the correct URL or followed a valid link.</p>
<div id="banner">
<object width="728" height="90"><param name="movie" value="http://74.53.143.237/images/hg728x90.swf">
<embed src="http://74.53.143.237/images/hg728x90.swf?clickTAG=http://secure.hostgator.com/cgi-bin/affiliates/clickthru.cgi?id=page404" width="728" height="90"></embed>
</object>
</div>
<div id="hostedby">This site is hosted by HostGator!</div>
<div id="coupon">Build your website today for 1 cent! Coupon code: "404PAGE"</div>
<div id="getstarted"><a href="http://www.hostgator.com/?utm_source=internal&utm_medium=link&utm_campaign=page404" title="HostGator Web Hosting" >CLICK HERE TO GET STARTED</a></div>
</div>
<div style="clear:left;"></div>
</div>
<div id="bottom404"></div>
</div>
</body>
</html>