【实战】采集某篇文章的标题

<%
'编码转换
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

'获取全部内容
Function GetBody(weburl)
    Set Retrieval = CreateObject("Msxml2.ServerXMLHTTP")
    With Retrieval
        .Open "Get", weburl, False, "", ""
        .Send
        GetBody = .ResponseBody
    End With
    GetBody = BytesToBstr(GetBody,"GB2312")
    Set Retrieval = Nothing
End Function

'获取GetBody中指定内容
Function GetSpcBody(wstr,start,over)
    Dim RegEx
    Set RegEx = New Regexp'设置配置对象
    RegEx.IgnoreCase = True'忽略大小写
    RegEx.Global = True'设置为全文搜索
    RegEx.Pattern = "" & start & "(.+?)" & over & "" '正则表达式
    Set Matches =RegEx.Execute(wstr)'开始执行配置
    GetSpcBody=""
    For Each Match in Matches
    GetSpcBody = GetSpcBody & RegEx.replace(Match.Value,"$1") '循环匹配
    Next
    set RegEx=nothing
End Function

'获取某网址指定内容
Function GetBodyByUrl(weburl,start,over)
    GetBodyByUrl=GetSpcBody(GetBody(weburl),start,over)
End function

Dim content
content=GetBodyByUrl("http://article.rongshuxia.com/viewart.rs?aid=3913735","<title>","</title>")
response.write "该文章的标题为:" & content
%>


------------------------------------------------------------------------
2012-02-09:Microsoft.XMLHTTP改为Msxml2.ServerXMLHTTP。

上一篇: RegExp 对象的属性和方法
下一篇: 单词发音免费查
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
最新日志:
评论: 1 | 引用: 0 | 查看次数: 4444
发表评论
登录后再发表评论!