当前位置:asp编程网>技术教程>Asp教程>  正文

asp实现网站友情链接检查程序的代码

2011-11-28 08:29:21   来源:网络    作者:佚名   浏览量:2038   收藏
asp查询网页的友情链接数量和具体的链接网址,本例没有排除二级(及以上)的域名,没有判断重复的外链,需要的可以自己加强一下。
<form action="">URL:<input name="url_" /><input type="submit" name="submit" value="查询" /></form> 
<% 
    If Request("url_")<>"" Then 
        SenFe_GetUrl Request("url_") 
    End If 
    Sub SenFe_GetUrl(sUrl) 
        Dim sContent, sDomian, oTempReg, I, oMatches, cMatch, sUrl_ 
        sUrl = LCase(sUrl) 
        If Left(sUrl, 7)="http://" Then 
            sDomian = Mid(sUrl, 8) 
        Else 
            sDomian = sUrl 
            sUrl = "http://" & Url 
        End If 
        If InStr(sDomian, "/") Then sDomian = Split(sDomian, "/")(0) 
        sContent = SenFe_GetData(sUrl) 
        Set oTempReg = New RegExp 
        With oTempReg 
            .IgnoreCase = True 
            .Global = True 
            .Pattern = "(http:(\/\/|\\\\)(([\w\/\\\+\-~`@:%])+\.)+([\w\/\\\.\=\?\+\-~`@\’:!%#]|(&)|&)+)" 
                Set oMatches = .Execute(sContent) 
                For Each cMatch In oMatches 
                sUrl_ = LCase(cMatch.Value) 
                If InStr(sUrl_, sDomian)=0 Then 
                    Response.Write(sUrl_ & "<br />" & VbCrLf) 
                End If 
                Next 
        End With 
        Set oTempReg = Nothing 
    End Sub 
    Function SenFe_GetData(sUrl) 
        Dim oXmlHttp : Set oXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP") 
        With oXmlHttp 
            .Open "GET",sUrl,False 
            .SetRequestHeader "Referer",sUrl 
            .Send 
            SenFe_GetData = SenFe_BytesToBstr(.ResponseBody,"GB2312") 
        End With 
        Set oXmlHttp = Nothing 
    End Function 
    Function SenFe_BytesToBstr(sBody, sCset) 
        Dim oAdos : Set oAdos = Server.CreateObject("Adodb.Stream") 
        With oAdos 
            .Type = 1 
            .Mode = 3 
            .Open 
            .Write sBody 
            .Position = 0 
            .Type = 2 
            .Charset = sCset 
            SenFe_BytesToBstr = .ReadText 
            .Close 
        End With 
        Set oAdos = Nothing 
    End Function 
%>
(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)


关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网