C#读取html标签中的数据
问题描述:
如何读取html标签(如<strong>
)之间的数据。例如。C#读取html标签中的数据
<strong id="food">40</strong>
如何从那里检索整数40?我试图
myBrowser.Document.GetElementById("food").GetAttribute("value");
答
我相信你正在寻找InnerText。
+0
或者在这里,InnerHTML会做到这一点,因为SLaks在我之前发布。 – 2012-02-29 18:26:59
答
的innerText
[STAThread]
static void Main(string[] args)
{
WebBrowser w = new WebBrowser();
w.Navigate(String.Empty);
HtmlDocument doc = w.Document;
doc.Write("<html><head></head><body><p id=\"food\">40</p></body></html>");
Console.WriteLine(doc.GetElementById("food").InnerText);
Console.ReadKey();
}
也许40是食品的则firstChild? – user1096188 2012-02-29 18:24:18
http://*.com/questions/56107/what-is-the-best-way-to-parse-html-in-c 这就是我在我的应用程序中使用。 – 2012-02-29 18:25:05
你确定这是C#吗?看起来更像JavaScript。 – Paddy 2012-02-29 18:25:20