IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機(jī)版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置:首頁網(wǎng)絡(luò)編程Asp編程 → ASP采集中獲取網(wǎng)頁內(nèi)所需的html代碼

ASP采集中獲取網(wǎng)頁內(nèi)所需的html代碼

時(shí)間:2015/6/28來源:IT貓撲網(wǎng)作者:網(wǎng)管聯(lián)盟我要評(píng)論(0)

有時(shí)候,需要獲取網(wǎng)頁的html代碼,如新聞采集。采集之前,首頁要得到被采集的頁面的html代碼,然后根據(jù)代碼,分析出你想要得到的內(nèi)容,最后將得到的內(nèi)容保存到自己的數(shù)據(jù)庫

function.asp


<%
Function getHTTPPage(url)
On Error Resume Next
dim http
set http=Server.createobject("Microsoft.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
Response.Write "<p align='center'><font color='red'>
<b>服務(wù)器獲取文件內(nèi)容出錯(cuò)</b></font></p>"
Err.Clear
End If 
End Function

Function BytesToBstr(body,Cset)
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 = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
%>

index.asp

<!--#include file="function.asp"-->
<%
url="https://www.google.cn"
response.write getHTTPPage(url)
%>

關(guān)鍵詞標(biāo)簽:代碼,網(wǎng)頁,獲取,集中,

相關(guān)閱讀

文章評(píng)論
發(fā)表評(píng)論

熱門文章 Active Server Pages 錯(cuò)誤 'ASP 0131'解決方Active Server Pages 錯(cuò)誤 'ASP 0131'解決方

相關(guān)下載

人氣排行 ASP下標(biāo)越界的解決方法ASP代碼中如何屏蔽ip地址 禁止某IP段訪問網(wǎng)站“文件共享鎖定數(shù)溢出” 原因及解決方法無法寫入數(shù)據(jù)庫的解決方法如何用ASP來獲取客戶端真實(shí)IP的地址用Asp編程實(shí)現(xiàn)QQ的在線情況查詢ASP常用函數(shù)列表ASP用FSO生成HTML簡(jiǎn)單實(shí)例+詳解[原創(chuàng)]