2012-09-06 32 views
0

您好,我需要一个正则表达式来获得本地域的所有链接没有外部网站。 到现在我有这个,但只返回页面外经典的ASP正则表达式来获取本地域的所有页面

<%function getPage(strURL) 
dim strBody, objXML 

set objXML = CreateObject("Msxml2.ServerXMLHTTP.6.0") 
    objXML.Open "GET", strURL, False 
    'objXML.setRequestHeader "User-Agent", "ddd" '=== falsify the agent 
    'objXML.setRequestHeader "Content-Type", "text/html; Charset:ISO-8859-1" 
    'objXML.setRequestHeader "Content-Type", "text/html; Charset:UTF-8" 
    objXML.Send 
    status = objXML.status 
if err.number <> 0 or status <> 200 then 
    if status = 404 then 
     Response.Write "[EFERROR]Page does not exist (404)." 
    elseif status >= 401 and status < 402 then 
     Response.Write "[EFERROR]Access denied (401)." 
    elseif status >= 500 and status <= 600 then 
     Response.Write "[EFERROR]500 Internal Server Error on remote site." 
    else 
     Response.write "[EFERROR]Server is down or does not exist." 
    end if 
     end if 
    strBody = objXML.responseText 

set objXML = nothing 
getPage = strBody 
'First, create a reg exp object 
Dim objRegExp 
Set objRegExp = New RegExp 

objRegExp.IgnoreCase = True 
objRegExp.Global = True 
objRegExp.Pattern = "<a\s+href=""http://(.*?)"">\s*((\n|.)+?)\s*</a>" 

'Display all of the matches 
Dim objMatch 
For Each objMatch in objRegExp.Execute(strBody) 
    Response.Write("http://" & objMatch.SubMatches(0) & "<br>") 
Next 

end function 


getPage("http://www.google.com") 
%> 

谢谢

+0

我试着做一种蜘蛛从主页获取所有内部链接,并向我展示屏幕 – Teodor

回答

0

或许说明明显,但如果你在寻找“localdomain.com”链接是不是这只是

objRegExp.Pattern = "<a\s+href=""http://(.*?)localdomain\.com"">\s*((\n|.)+?)\s*</a>" 

编辑: 的正则表达式模式或许可以用在URL中传递的是这样的:

objRegExp.Pattern = "<a\s+href=""" & strURL & "(.*?)"">\s*((\n|.)+?)\s*</a>" 

检索匹配将需要追加该strURL太:

For Each objMatch in objRegExp.Execute(strBody) 
    Response.Write("http://" & strURL & objMatch.SubMatches(0) & "<br>") 
Next 
+0

谢谢。我发布了这个,因为我不知道正则表达式...你的模式不会在我的例子中返回任何东西。我只需要一个从主页返回localdomain URL的模板。 – Teodor

+0

噢,对不起..我急匆匆地回答......你已经把你的网址从课程中传递出去了......它应该使用在URL中传递的...我将编辑我的答案。 – AardVark71

+0

它不会做我所期望的..它应该显示我在strURL的索引页中的所有网址的列表,这是strURL ..我的意思是如果我看到有一个链接到yahoo.com忽略..仅向我展示索引页面上strURL上的链接..所以只有在google.com上托管的页面 – Teodor

相关问题