从网页上阅读特定内容?

时间:2011-04-11 13:16:55

标签: c# xml

我正在尝试创建一个应用程序(在C#中),我必须从wiktionary.com或dictionary.com等网站获得一些含义。但我从来没有使用过Xml,也没有使用过网页。

我设法从网页上获得了响应(例如,来自dictionary.com的特定单词)(我希望是xml格式)。

这就是我对'Hello'这个词的看法。:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<!--attributes for answers reference-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/">
<head>
<title>
Hello | Define Hello at Dictionary.com
</title>
<meta name="description" content="Hello definition, (used to express a greeting, answer a telephone, or attract attention.) See more."/>
<meta name="keywords" content="hello, online dictionary, English dictionary, hello definition, define hello, definition of hello, hello pronunciation, hello meaning, hello origin, hello examples"/>
<link rel="canonical" href="http://dictionary.reference.com/browse/hello"/>
<meta property="og:title" content="the definition of hello"/>
<meta property="og:site_name" content="Dictionary.com"/>
<meta property="og:image" content="http://sp2.dictionary.com/en/i/dictionary/facebook/dictionary_logo.png"/>

现在我想从响应中解析以下字符串。

used to express a greeting, answer a telephone, or attract attention.

我尝试使用XmlReader但卡住了。有人可以帮我看一下这个内容吗?

2 个答案:

答案 0 :(得分:3)

您可以使用HTML Agility Pack轻松解析HTML。

HtmlDocument doc = new HtmlDocument();
// replace with your own content
doc.Load("file.htm");
foreach(HtmlNode meta in doc.DocumentElement.SelectNodes("/meta[@name='description'"])
{
    HtmlAttribute att = meta["content"];
    Consol.WriteLine( att.Value );
}

答案 1 :(得分:3)

您可以使用http://services.aonaware.com/之类的网络服务,这对您和目标网站来说更好:-)。

http://words.bighugelabs.com/api.php是另一个选项,它有一个更简单的API

相关问题