这样也可以
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如何调用openai的api实现知识讲解类动画讲解视频的合成?
html如何直接调用openai的api实现海报可视化设计及文本描述生成可编辑海报?
f12前端调试如何找出按钮点击事件触发的那段代码进行调试?
abcjs如何将曲谱播放后导出mid和wav格式音频下载?
python如何将曲子文本生成音乐mp3或wav、mid文件
python中mp3、wav音乐如何转成mid格式?
js在HTML中如何将曲谱生成音乐在线播放并下载本地?
python如何实现在windows上通过键盘来模拟鼠标操作?
python如何给win10电脑增加文件或文件夹右键自定义菜单?
python如何将音乐mp3文件解析获取曲调数据?