0

これをvar source="<p><a href="http://in.news.yahoo.com/googles-stock-split-raises-questions-023232813.html"><img src="http://l.yimg.com/bt/api/res/1.2/TRLtYhdbTvFcX_GOU_0S4g--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2012-04-14T023232Z_5_CBRE83B1MAL00_RTROPTP_2_USA.JPG" width="130" height="86" alt="People visit Google's stand at the National Retail Federation Annual Convention and Expo in New York" align="left" title="People visit Google's stand at the National Retail Federation Annual Convention and Expo in New York" border="0" /></a>(Reuters) - An unusual stock split designed to preserve Google Inc founders' control of the Web search leader raised questions and some grumbling on Wall Street, even as investors focused on the company's short-term business concerns. Shares of Google closed 4 percent lower at $624.60 on Friday, driven by deepening worries about its search ad rates and payments to partners. The declining search trends underscored investor uncertainty about Google's growth prospects and unease about the company's pending $12.5 billion acquisition of Motorola Mobility. ...</p><br clear="all"/>" 解析/スクレイプして、変数のリンクアドレス、つまりhttp://in.news.yahoo.com/googles-stock-split-raises-questions-023232813.html別の変数の画像srcを取得する必要があります。</a>との間の説明テキストも必要</p>です..私がひどく立ち往生しているのを助けてください...

4

1 に答える 1

1

HtmlAgilityPackを使用して以下のコードスニペットを試してください

var source = @"<p><a href=""http://in.news.yahoo.com/googles-stock-split-raises-questions-023232813.html""><img src=""http://l.yimg.com/bt/api/res/1.2/TRLtYhdbTvFcX_GOU_0S4g--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2012-04-14T023232Z_5_CBRE83B1MAL00_RTROPTP_2_USA.JPG"" width=""130"" height=""86"" alt=""People visit Google's stand at the National Retail Federation Annual Convention and Expo in New York"" align=""left"" title=""People visit Google's stand at the National Retail Federation Annual Convention and Expo in New York"" border=""0"" /></a>(Reuters) - An unusual stock split designed to preserve Google Inc founders' control of the Web search leader raised questions and some grumbling on Wall Street, even as investors focused on the company's short-term business concerns. Shares of Google closed 4 percent lower at $624.60 on Friday, driven by deepening worries about its search ad rates and payments to partners. The declining search trends underscored investor uncertainty about Google's growth prospects and unease about the company's pending $12.5 billion acquisition of Motorola Mobility. ...</p><br clear=""all""/>";

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(source);

var paraNode = doc.DocumentNode.SelectSingleNode("//p");
var desc = paraNode.InnerText;

var anchorNode = doc.DocumentNode.SelectSingleNode("//p/a");
var link = anchorNode.GetAttributeValue("href", null);

var imgNode = doc.DocumentNode.SelectSingleNode("//p/a/img");
var src = imgNode.GetAttributeValue("src", null);

これを行うには多くの方法がありますが、これは仕事を成し遂げるためのアプローチの1つにすぎません。それはあなたにそれをどのように行うかについての考えを与えますHtmlAgilityPackXPATHこのようなものを解析している間、あなたに多くの力を与えるでしょう。

于 2012-04-15T18:33:27.630 に答える