2012-04-15 6 views
0

Ich habe 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"/>" Jetzt muss ich analysieren/verschrotten, um die Linkadresse in einer Variablen, d. H. http://in.news.yahoo.com/googles-stock-split-raises-questions-023232813.html und das Bild src in einer separaten Variablen zu erhalten. Ich brauche auch den Beschreibungstext zwischen </a> und </p> .. helfen bitte mir schlecht stecken bin ...Wie verwerfen Sie einen bestimmten Teil einer HTML-Seite mit regulärem Ausdruck oder HTMLAgilityPack in Visual Studio 2010 mit C#?

+0

ich tat es mit htmlagility pack ... danke !!! – Vikram

Antwort

1

Versuchen Sie, den folgenden Code-Schnipsel HtmlAgilityPack mit

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); 

Es gibt viele Möglichkeiten, dies zu tun, aber das ist nur einer der Ansätze, um die Arbeit zu erledigen. Es gibt Ihnen eine Idee, wie man es mit HtmlAgilityPack macht. XPATH wird Ihnen viel Kraft beim Parsen solcher Sachen geben.

+0

Vielen Dank .. War wirklich hilfreich .. – Vikram