[點晴永久免費OA]C#正則獲取指定內容
當前位置:點晴教程→點晴OA辦公管理信息系統
→『 經驗分享&問題答疑 』
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
using System.Net;
string url = "https://ipchaxun.com/253.26.12.3/";
WebRequest wrt = WebRequest.create(url);
wrt.Credentials = CredentialCache.DefaultCredentials;
WebResponse wrp = wrt.GetResponse();
StreamReader sr = new StreamReader(wrp.GetResponseStream(), Encoding.UTF8);
string html = sr.ReadToEnd();
string pattern = "<span class=\"name\">歸屬地:</span><span class=\"value\">(?<key>.*?)</span>";
Regex regex = new Regex(pattern, RegexOptions.None);
Match match = regex.Match(html);
string city = match.Groups["key"].Value;
該文章在 2022/6/8 18:16:05 編輯過 |
關鍵字查詢
相關文章
正在查詢... |