<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><br /><%<br />'功能:asp採集代碼<br />'作者:wangsdong<br />'備忘:支援原創程式,請保留此資訊,謝謝<br />url="http://sports.sina.com.cn/k/2008-09-15/04593948756.shtml"<br />str=getHTTPPage(url)<br />title=strcut(str,"<h1 id=""artibodyTitle"" style=""color:#03005C;"">","</h1>",2)<br />content=strcut(str,"<!-- 本文內容 begin -->","<!-- 本文內容 end -->",2)<br />response.write "新聞標題<br><b>"&title&"</b><br><br><br>新聞內容:<br>"&content<br />Function getHTTPPage(url)<br />On Error Resume Next<br />dim http<br />set http=Server.createobject("Microsoft.XMLHTTP")<br />Http.open "GET",url,false<br />Http.send()<br />if Http.readystate<>4 then<br />exit function<br />end if<br />getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")<br />set http=nothing<br />If Err.number<>0 then<br />Response.Write "<p align=’center’><font color=’red’><b>伺服器擷取檔案內容出錯</b></font></p>"<br />Err.Clear<br />End If<br />End Function </p><p>Function BytesToBstr(body,Cset)<br />dim objstream<br />set objstream = Server.CreateObject("adodb.stream")<br />objstream.Type = 1<br />objstream.Mode =3<br />objstream.Open<br />objstream.Write body<br />objstream.Position = 0<br />objstream.Type = 2<br />objstream.Charset = Cset<br />BytesToBstr = objstream.ReadText<br />objstream.Close<br />set objstream = nothing<br />End Function </p><p>'截取字串,1.包括起始和終止字元,2.不包括<br />Function strCut(strContent,StartStr,EndStr,CutType)<br />Dim strHtml,S1,S2<br />strHtml = strContent<br />On Error Resume Next<br />Select Case CutType<br />Case 1<br />S1 = InStr(strHtml,StartStr)<br />S2 = InStr(S1,strHtml,EndStr)+Len(EndStr)<br />Case 2<br />S1 = InStr(strHtml,StartStr)+Len(StartStr)<br />S2 = InStr(S1,strHtml,EndStr)<br />End Select<br />If Err Then<br />strCute = "<p align=’center’>沒有找到需要的內容。</p>"<br />Err.Clear<br />Exit Function<br />Else<br />strCut = Mid(strHtml,S1,S2-S1)<br />End If<br />End Function<br />%>