How to read a image url from a rss with syndicationFeed?

后端 未结 3 1533
借酒劲吻你
借酒劲吻你 2021-02-06 14:30

How to get the image url? supposing that the tag is

    

        
3条回答
  •  被撕碎了的回忆
    2021-02-06 15:07

    For example Google RSS keeps all images within a summury.

    So u can extract it by this code:

    List rssItems = new List();
                        Stream stream = e.Result;
                        XmlReader response = XmlReader.Create(stream);
                        SyndicationFeed feeds = SyndicationFeed.Load(response);
                        foreach (SyndicationItem f in feeds.Items)
                        {
                            RssFeedItem rssItem = new RssFeedItem();
    
                            rssItem.Description = f.Summary.Text;
    
     const string rx =  @"(?<=img\s+src\=[\x27\x22])(?[^\x27\x22]*)(?=[\x27\x22])"; 
                            foreach (Match m in Regex.Matches(f.Summary.Text, rx, RegexOptions.IgnoreCase | RegexOptions.Multiline))
                            {
                                string src = m.Groups[1].Value;
                                if (src.StartsWith("//")) // Google RSS has it
                                {
                                    src = src.Replace("//", "http://");
                                }
    
                                rssItem.ImageLinks.Add(src);
                            }
    

提交回复
热议问题