コード例 #1
0
ファイル: Wrapper.cs プロジェクト: Rimysoft/OlbiaNovaAPI
        public Notizia[] GetAllNews()
        {
            //
            List<Notizia> notizie = new List<Notizia>();
            var r = XmlReader.Create("http://www.olbianova.it/notizies/feed/rss/news?format=feed");
            var albums = SyndicationFeed.Load(r);
            r.Close();
            try
            {
                foreach (var item in albums.Items)
                {
                    Notizia not = new Notizia();
                    //
                    not.Title = item.Title.Text;
                    not.Description = EncodeJsString(item.Summary.Text);

                    not.Url = item.Id;
                    not.ImgUrl = getImage(item.Summary.Text);
                    //
                    notizie.Add(not);
                }
            }
            catch (Exception)
            {

            }

            return notizie.ToArray();
        }
コード例 #2
0
ファイル: Wrapper.cs プロジェクト: Rimysoft/OlbiaNovaAPI
        /*
                article class="wk-content">
        <div class="wk-zoo-item layout-article clearfix">

                <h3 class="title">
                 <a title="Che meraviglia la festa di Giovannino in Via Lucca" href="/notizies/item/che-meraviglia-la-festa-di-giovannino-in-via-lucca">Che meraviglia la festa di Giovannino in Via Lucca</a>
         * </h3>

                <p class="meta">
                <span class="element element-date first last">
             Domenica, 04 Agosto 2013</span>	</p>

                <div class="description">
                <div class="element element-text first last">
            E' nata come una festa per pochi amici ora, dopo 21 anni, si fa a gara per farsi invitare.  </div>	</div>

                <div class="media media-bottom">

            <a href="/notizies/item/che-meraviglia-la-festa-di-giovannino-in-via-lucca"   title="Il gruppo &quot;Song of the Wind&quot;"  ><img src="http://www.olbianova.it/cache/com_zoo/images/8_pink_9929a44f2d29ea8ea3900d0b9ace2a3a.jpg" title="Il gruppo &quot;Song of the Wind&quot;" alt="Il gruppo "Song of the Wind"" width="950" height="534" /></a>
            </div>

        </div>
        */
        private Notizia GetNotizia(string input)
        {
            Notizia nt = new Notizia();
            if (input.Contains("<a title=\""))
            {
                int pos = input.IndexOf("<a title=\"");
                if (pos > 0)
                {
                    for (int i = pos; i < input.Length; i++)
                    {
                        if (i + 8 < input.Length)
                        {
                            bool bFindUrl = false;
                            if (input.Substring(i, 8) == "\" href=\"")
                            {
                                nt.Title = input.Substring(pos + 10, i - (pos + 10));
                                for (int j = i + 8; j < input.Length; j++)
                                {
                                    if (j + 2 < input.Length)
                                    {
                                        if (input.Substring(j, 2) == "\">")
                                        {
                                            nt.Url = "http://www.olbianova.it" + input.Substring(i + 8, j - (i + 8));
                                            bFindUrl = true;
                                            break;
                                        }
                                    }
                                }
                                if (bFindUrl)
                                    break;
                            }
                        }
                    }
                }
            }
            if (input.Contains("<div class=\"element element-text first last\">"))
            {
                int pos = input.IndexOf("<div class=\"element element-text first last\">");
                if (pos > 0)
                {
                    for (int i = pos; i < input.Length; i++)
                    {
                        if (i + 6 < input.Length)
                        {
                            if (input.Substring(i, 6) == "</div>")
                            {
                                nt.Description = input.Substring(pos, i - pos).Replace("<div class=\"element element-text first last\">", "").Trim();
                                break;
                            }
                        }
                    }
                }
            }
            //
            if (input.Contains("img src=\"http:"))
            {
                int pos = input.IndexOf("img src=\"http:");
                for (int i = pos; i < input.Length; i++)
                {
                    if (i + 6 < input.Length)
                    {
                        if (input.Substring(i, 7) == "\" title")
                        {
                            nt.ImgUrl = input.Substring(pos, i - pos).Replace("img src=\"", "").Trim();
                            break;
                        }
                    }
                }
            }
            else if (input.Contains("data-src=\"http:"))
            {
                int pos = input.IndexOf("data-src=\"http:");
                for (int i = pos; i < input.Length; i++)
                {
                    if (i + 6 < input.Length)
                    {
                        if (input.Substring(i, 7) == "\" title")
                        {
                            nt.ImgUrl = input.Substring(pos, i - pos).Replace("data-src=\"", "").Trim();
                            break;
                        }
                    }
                }
            }
            return nt;
        }