Reputation: 1335
I want to get plain text in the body tag.
Markup:
**simple text 1**
<div>------</div>
<font>-------</font>
**simple text 2**
Code:
foreach (HtmlElement elm in webBrowser1.Document.Body.All)
{
//get simple text
}
Upvotes: 0
Views: 1457
Reputation: 138
Simply:
string plainText = webBrowser1.Document.Body.InnerText;
Upvotes: 1
Reputation: 3299
Try following way: you can get all text which are shown in browser preview by using following technique.
string plainText= StripHTML(webBrowser1);// call this way-----
public string StripHTML(WebBrowser webp)
{
try
{
Clipboard.Clear();
webp.Document.ExecCommand("SelectAll", true, null);
webp.Document.ExecCommand("Copy", false, null);
}
catch (Exception ep)
{
MessageBox.Show(ep.Message);
}
return Clipboard.GetText();
}
Upvotes: 0
Reputation: 1335
I find this easy way :
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(webBrowser1.Document.Body.InnerHtml);
foreach (var elm in htmlDoc.DocumentNode.Descendants())
{
if (elm.NodeType == HtmlNodeType.Text)
{
//simple text is #text
var innerText=elm.InnerText;
}
}
have a good time.
Upvotes: 0