如何从网页取得文字? [英] How to get text off a webpage?

查看:135
本文介绍了如何从网页取得文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C#中的网页中获取文本。

我不想获取HTML,我想要的是网页的真实文本。就像我输入< b> cake< / b> ,我想要的是蛋糕,而不是标签。

I want to get text off of a webpage in C#.
I don't want to get the HTML, I want the real text off of the webpage. Like if I type "<b>cake</b>", I want the cake, not the tags.

推荐答案

http://htmlagilitypack.codeplex.com

这是用于解析HTML的非常好的库,您需要使用以下代码:

That's very fine library for parse HTML, for your requirement use this code:

    HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
    HtmlAgilityPack.HtmlDocument doc = web.Load("Yor Path(local,web)"); 
    var result=doc.DocumentNode.SelectNodes("//body//text()");//return HtmlCollectionNode
    foreach(var node in result)
    {
        string AchivedText=node.InnerText;//Your desire text
    }

这篇关于如何从网页取得文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆