asp 採集代碼

來源:互聯網
上載者:User

<%@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 />%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.