2010-11-26 9 views
1

Amazon RSS 피드에서 데이터를 가져 오는 RSS 피드를 작업 중입니다. C# .NET Compact Framework 3.5를 사용하고 있습니다. 책의 제목, RSS 피드의 노드에서 발행 한 날짜 등을 얻을 수 있습니다. 그러나 책의 가격은 설명 노드에서 전체 HTML 힙에 임베드됩니다. 어떻게하면 HTML만을로드하지 않고 가격 만 추출 할 수 있습니까?amazon의 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>을 치기 전까지 followign char를 추출하십시오.

html을로드 할 필요가 없습니다. 설명에 alraedy가 있습니다.

그게 효과가 있습니까?

1

그 설명은 정말 안좋아 보입니다. 다른 RSS 피드 버전을 구할 수있는 가능성이 없으면 설명에 포함 된 HTML을 구문 분석하는 것이 유일한 해결책이라고 생각합니다.

HTML Agility Pack (사용하지 않았지만 .NET에서 HTML 구문 분석에 권장되는 솔루션) 또는 정규 표현식이나 텍스트 검색을 사용하여 해당 태그를 찾아 가격을 추출 할 수 있습니다. 조금 나빠서 RSS가 바뀌면 많은 변화를 만들어야 할 필요가 생길 수있다.)

편집 : 정규식과 결합 된 문자열 검색을 수행했지만 유지 관리는 어렵지만 고려해야한다. 당신의 사건과 그것이 단지 하나의 가치를위한 것이라면 그것은 괜찮을 것입니다.

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(); 
관련 문제