2010-11-26 27 views
1

私は書籍のAmazon RSSフィードからデータを引き出すRSSフィードを作成しています。私はC#.NET Compact Framework 3.5を使用しています。私は本のタイトル、公開された日付などをRSSフィードのノードから得ることができます。しかし、書籍の価格は、記述ノードのHTMLのヒープ全体に埋め込まれています。 HTMLの読み込みではなく、価格だけを抽出する方法は?説明ノードの中央にアマゾンのRSSフィードからフィードを取得

if (nodeChannel.ChildNodes[i].Name == "item") 
{ 
    nodeItem = nodeChannel.ChildNodes[i]; 
    row = new ListViewItem(); 
    row.Text = nodeItem["title"].InnerText; 
    row.SubItems.Add(nodeItem["description"].InnerText); 
    listBooks.Items.Add(row); 
} 

価格の一例

<description><![CDATA[ <div class="hreview" style="clear:both;"> <div class="item">  <div style="float:left;" class="tgRssImage"><a class="url" href="http://rads.stackoverflow.com/amzn/click/B0013FDM7E"><img src="http://ecx.images-amazon.com/images/I/51MvRlzFlpL._SL160_SS160_.jpg" width="160" alt="I Am Legend (Widescreen Single-Disc Edition)" class="photo" height="160" border="0" /></a></div> <span class="tgRssTitle fn summary">I Am Legend (Widescreen Single-Disc Edition) (<span class="tgRssBinding">DVD</span>)<br />By <span class="tgRssAuthor">Will Smith</span><br /></span> </div> <div class="description"> <br /> <span style="display: block;" class="tgRssPriceBlock"><span class="tgProductPriceLine"><a href="http://rads.stackoverflow.com/amzn/click/B0013FDM7E">Buy new</a>: <span class="tgProductPrice">$5.49</span></span><br /><span class="tgProductUsedPrice"><a href="http://rads.stackoverflow.com/amzn/click/B0013FDM7E" id="tag_rso_rs_eofr_used">285 used and new</a> from <span class="tgProductPrice">$1.00</span></span><br /></span> <span class="tgRssReviews">Customer Rating: <img src="http://g-ecx.images-amazon.com/images/G/01/x-locale/common/customer-reviews/stars-3-5._V192240731_.gif" width="64" alt="3.6" align="absbottom" height="12" border="0" /><br /></span> <br /> <span class="tgRssProductTag"></span> <span class="tgRssAllTags">Customer tags: <a href="http://www.amazon.com/tag/science%20fiction/ref=tag_rss_rs_itdp_item_at">science fiction</a>(92), <a href="http://www.amazon.com/tag/will%20smith/ref=tag_rss_rs_itdp_item_at">will smith</a>(79), <a href="http://www.amazon.com/tag/horror/ref=tag_rss_rs_itdp_item_at">horror</a>(51), <a href="http://www.amazon.com/tag/action/ref=tag_rss_rs_itdp_item_at">action</a>(43), <a href="http://www.amazon.com/tag/adventure/ref=tag_rss_rs_itdp_item_at">adventure</a>(34), <a href="http://www.amazon.com/tag/fantasy/ref=tag_rss_rs_itdp_item_at">fantasy</a>(33), <a href="http://www.amazon.com/tag/dvd/ref=tag_rss_rs_itdp_item_at">dvd</a>(30), <a href="http://www.amazon.com/tag/movie/ref=tag_rss_rs_itdp_item_at">movie</a>(20), <a href="http://www.amazon.com/tag/zombies/ref=tag_rss_rs_itdp_item_at">zombies</a>(14), <a href="http://www.amazon.com/tag/i%20am%20legend/ref=tag_rss_rs_itdp_item_at">i am legend</a>(6), <a href="http://www.amazon.com/tag/bad%20sci-fi/ref=tag_rss_rs_itdp_item_at">bad sci-fi</a>(4), <a href="http://www.amazon.com/tag/mutants/ref=tag_rss_rs_itdp_item_at">mutants</a>(4)<br /></span> </div></div>]]></description> 

$ 5.49どこか

+0

価格を含むHTMLコードの例を挙げることができますか? – Rox

+0

ちょうどそれがありがとう –

答えて

1

それはダムアイデアことが、どのようにした後、文字列の検索を行うことについての可能性があり、その混乱にありますclass="tgProductPrice">?終了タグ</span>を押すまで、フォローイングの文字を抽出します。

あなたはhtmlを読み込む必要はありませんが、あなたは説明の中にそれを持っています。

これは機能しますか?

1

その説明は本当に悪くて、もしあなたがそのRSSフィードの別のバージョンを入手する可能性がなければ、唯一の解決策はあなたがその記述にあるHTMLを解析することだと思います。

HTML Agility Pack(これは使用していませんが、.NETのHTML解析にはおすすめのソリューションです)、正規表現やテキスト検索を使用してそのタグを見つけて価格を抽出しますRSSが変更された場合、多くの変更を加える必要が生まれる可能性があります)

編集:私は正規表現と組み合わせて文字列検索をやってきましたが、それは維持する悪夢でしたあなたのケースとそれは1つの値のためだけだ、それは大丈夫かもしれません。

0
using CsQuery; //get CsQuery from nuget packages 
path = textBox1.Text; 
     var dom = CQ.CreateFromUrl(path); 
     var divContent = dom.Select("#priceblock_ourprice").Text(); 
     //priceblock_ourprice is an id of span where price is written 
     label1.Text = divContent.ToString(); 
関連する問題