大家好,请教一个问题,在html代码中找出所有的url并替换成我要的url格式。
比如<html>
<head>ssss</head>
<body>
<a href="http://www.ddd1.com" target="_blank">dsafsdfsdfsdfsf</>
<a href="http://www.dsdafsdd.com/dd.aspx?ddds=1" target="_blank">dsafdfsf</>
<a href="http://www.ddsdafdfd.com/ddssfddd.aspx?ddds=2" target="_blank">dsafsdfsdafsdfasdfsdfsdfsf</>
<body>
</html>
能否找上面代码中的所有url并把url加密然后替换成下面的形式
<html>
<head>ssss</head>
<body>
<a href="goto.aspx?url=aa" target="_blank">dsafsdfsdfsdfsf</>说明aa为http://www.ddd1.com加密后的字符串
<a href="goto.aspx?url=bb" target="_blank">dsafdfsf</>说明bb为http://www.dsdafsdd.com/dd.aspx?ddds=1加密后的字符串
<a href="goto.aspx?url=cc" target="_blank">dsafsdfsdafsdfasdfsdfsdfsf</>说明cc为http://www.ddsdafdfd.com/ddssfddd.aspx?ddds=2加密后的字符串
<body>
</html>希望大家能够指点。

解决方案 »

  1.   

    如果你是不想让用户在URL地址栏内看到具体跳转的页面可以用server.urlEncode 结合server.urlDecode来实现string url="goto.aspx?url="+Server.URLEncode("http://www.ddd1.com");
      

  2.   

    提取HTML中的URL,这可以用正则的方法~但又要取出之来后,再加密,这就需要分两次操作了!我觉得可参考的方案是:1、用正则先将HTML中URL提取出来,并将原URL位置 用标记字符 ( 序号+带特殊符 ) 代替一下2、再把提取出来的URL 经过 Server.URLEncode 之后 再用REALPCE操作把 按标记好的 URL再代替回去。