这样也可以
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace HelloWorldApplication
{
class HelloWorld
{
public static string GetHtml(string url) {
string res = "";
WebClient client = new WebClient();
Stream stream = client.OpenRead(url);
StreamReader sr = new StreamReader(stream, Encoding.Default);
res = sr.ReadToEnd();
sr.Close();
client.Dispose();
return res;
}
static void Main(string[] args) {
//爬出网页html代码
string data=GetHtml("http://www.bfw.wiki");
//正则匹配链接地址
string regex = "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']";
Regex re = new Regex(regex);
MatchCollection matches = re.Matches(data);
System.Collections.IEnumerator enu = matches.GetEnumerator();
while (enu.MoveNext() && enu.Current != null)
{
//打印地址
Match match = (Match)(enu.Current);
Console.Write(match.Value + "\r\n");
}
}
}
}
网友回复
python如何实现torrent的服务端进行文件分发p2p下载?
如何在浏览器中录制摄像头和麦克风数据为mp4视频保存下载本地?
go如何编写一个类似docker的linux的虚拟容器?
python如何写一个bittorrent的种子下载客户端?
ai能通过看一个网页的交互过程视频自主模仿复制网页编写代码吗?
ai先写功能代码通过chrome mcp来进行测试功能最后ai美化页面这个流程能行吗?
vue在手机端上下拖拽元素的时候如何禁止父元素及body的滚动导致无法拖拽完成?
使用tailwindcss如何去掉响应式自适应?
有没有直接在浏览器中运行的离线linux系统?
nginx如何保留post或get数据进行url重定向?