用asp.net实现 取页面中的所有链接
程序员文章站
2022-06-23 18:33:55
private void page_load(object sender, system.eventargse) &nb...
private void page_load(object sender, system.eventargse)
{
//在此处放置用户代码以初始化页面
string url =//www.jb51.net;
system.net.httpwebrequesthttpreq;
system.net.httpwebresponsehttpres;
system.urihttpurl = new uri(url);
httpreq =(system.net.httpwebrequest)system.net.webrequest.create(httpurl);
httpreq.method= "get";
httpres= (system.net.httpwebresponse)httpreq.getresponse();
httpreq.keepalive= false;
system.io.streamreadersreader = newsystem.io.streamreader(httpres.getresponsestream(),system.text.encoding.getencoding("gb2312"));
stringres = sreader.readtoend();
//以下是利用正则表达式对获取的文本流进行过滤
stringstrregex = @"<a.+?a>";
system.text.regularexpressions.regexr;
system.text.regularexpressions.matchcollectionm;
r = newsystem.text.regularexpressions.regex(strregex,system.text.regularexpressions.regexoptions.ignorecase);
m =r.matches(res);
response.write("该页共有"+m.count + " 个超连接<br/>");
for (inti = 0; i < m.count; i++)
{
response.write(m[i].value+ "<br/>");
}
}
{
//在此处放置用户代码以初始化页面
string url =//www.jb51.net;
system.net.httpwebrequesthttpreq;
system.net.httpwebresponsehttpres;
system.urihttpurl = new uri(url);
httpreq =(system.net.httpwebrequest)system.net.webrequest.create(httpurl);
httpreq.method= "get";
httpres= (system.net.httpwebresponse)httpreq.getresponse();
httpreq.keepalive= false;
system.io.streamreadersreader = newsystem.io.streamreader(httpres.getresponsestream(),system.text.encoding.getencoding("gb2312"));
stringres = sreader.readtoend();
//以下是利用正则表达式对获取的文本流进行过滤
stringstrregex = @"<a.+?a>";
system.text.regularexpressions.regexr;
system.text.regularexpressions.matchcollectionm;
r = newsystem.text.regularexpressions.regex(strregex,system.text.regularexpressions.regexoptions.ignorecase);
m =r.matches(res);
response.write("该页共有"+m.count + " 个超连接<br/>");
for (inti = 0; i < m.count; i++)
{
response.write(m[i].value+ "<br/>");
}
}
上一篇: 最糟糕的感觉
下一篇: 关于shell命令的定向输出 2>&1
推荐阅读