Example #1
0
        /// <summary>
        /// 获取图片url
        /// </summary>
        /// <param name="html"></param>
        private void MatchImageUrl(string html, string host, string webUrl)
        {
            string          matchStr   = "<img[\\s^\\s]+src=\"(?<src>\\S+)\"";//分组命名
            string          imgUrl     = string.Empty;
            Regex           regex      = new Regex(matchStr, RegexOptions.IgnoreCase | RegexOptions.Compiled);
            MatchCollection collection = regex.Matches(html);

            foreach (Match item in collection)
            {
                imgUrl = item.Groups["src"].Value;

                //无效链接
                if (string.IsNullOrEmpty(imgUrl))
                {
                    continue;
                }

                if (!imgUrl.Contains("http"))
                {
                    imgUrl = "http://" + host + imgUrl;
                }
                //是否存在
                if (ImageUrlBLL.IsExistImageUrl(imgUrl))
                {
                    continue;
                }

                ImageUrlEntity imageUrlEnt = new ImageUrlEntity();
                imageUrlEnt.AddDate  = DateTime.Now;
                imageUrlEnt.Host     = host;
                imageUrlEnt.ImageUrl = imgUrl;
                imageUrlEnt.WebUrl   = webUrl;
                ImageUrlBLL.Insert(imageUrlEnt);
            }
        }
Example #2
0
 /// <summary>
 /// 获取头像URl
 /// </summary>
 /// <param name="strValue"></param>
 /// <param name="imageUrlEntity"></param>
 /// <returns></returns>
 public static string GetImageUrl(string strValue, ImageUrlEntity imageUrlEntity)
 {
     return(strValue.Replace("/50/", "/" + (int)imageUrlEntity + "/"));
 }