在站長(zhǎng)工具中,經(jīng)??吹脚袛嘁粋€(gè)頁(yè)面的關(guān)鍵詞密度,他是怎么實(shí)現(xiàn)的獲取外部網(wǎng)頁(yè)內(nèi)容的呢。是通過(guò)js的ajax,獲取后再計(jì)算。
下面是獲取外部網(wǎng)頁(yè)代碼的代碼。也可以查看效果:javascript讀取網(wǎng)頁(yè)代碼
下面是詳細(xì)代碼
<script language=javascript>
function check(url)
{
var xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
var chkUrl = url;
xmlHttp.open('get', chkUrl, false);
try{
xmlHttp.send();
}
catch(e){
window.alert('出現(xiàn)異常');
}
oSource.value=xmlHttp.responseText;
// alert(bytes2BSTR(xmlHttp.responseText));
fn.document.body.innerHTML="<base href='"+url+"'>"+xmlHttp.responseText;
}
</script>
<Script Language=Vbscript>
Function getHTTPPage(url)
on error resume next
dim http,code
set http= createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
code=bytes2BSTR(Http.responseBody)
oSource.value=code
fn.document.body.innerHTML="<base href='"+url+"'>"+code
set http=nothing
if err.number<>0 then err.Clear
End function
Function bytes2BSTR(vIn)
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 = strReturn
End Function
</script>
<body>
<div align="center">輸入域名點(diǎn)擊打開(kāi)即可獲取網(wǎng)站內(nèi)容: <br>
<textarea cols="100" rows="10" id="oSource"></textarea>
<br>
<input name=url value="http://m.bwnwqq.cn">
<input type=button value="打開(kāi)" onclick=getHTTPPage(url.value)><br>
</div>
更多信息請(qǐng)查看IT技術(shù)專欄