日期:2014-05-17  浏览次数:20752 次

如何获取网页中指定元素的字符
就是比如说网页中<text>aaaaaa<text>
aaaaaaaa是我要的内容
怎么获取并显示到textbox上
跪求答案

------解决方案--------------------
建议用HtmlAgilityPack,比正则好用。



[url=http://blog.csdn.net/dalmeeme/article/details/7191793]
------解决方案--------------------
http://zhoufoxcn.blog.51cto.com/792419/595344

http://blog.csdn.net/dalmeeme/article/details/7191793
------解决方案--------------------
C# code
//最前面加上using System.Text.RegularExpressions;

string HTML = "<html>...<p><text>aaaaaa<text></p>...</html>"; // 你的html代码
string result = Regex.Match(HTML, @"<text>(.+?)<text>").Groups[1].Value;
textBox1.Text = result;

------解决方案--------------------
C# code
//using System.Net;

WebClient client = new WebClient();
string HTML = client.DownloadString("http://www.google.com");
...

------解决方案--------------------
启用单行模式试试string result = Regex.Match(HTML, @"(?s)<br />(.+?)<br />").Groups[1].Value;