我需要使用 C# win 表单阅读网站的标题。那么最好的方法是什么。我在谷歌上搜索但没有找到任何人。
提前致谢
请您参考如下方法:
您想使用在 System.Net.WebClient 命名空间中找到的 WebClient 对象。
using System.Net;
使用 WebClient,您可以将整个网站下载为字符串,然后使用该字符串执行任何您想做的事情。 :)
示例:
WebClient client = new WebClient();
string content = wc.DownloadString("http://www.google.com");
然后只要你想要它就解析字符串。 :) 在此示例中,您可能希望找到标题元素并像这样提取标题:
string title = content.Substring(content.IndexOf("<title>"), content.IndexOf("</title>") - content.IndexOf("<title>")).Replace("<title>", "").Trim();
希望对您有所帮助。 :)
