C# 正则获取网页图片地址

                                         string FaPiaoUrl = "";
                                              string FaPiaoImageUrl = "";                 

                              string HTMLSTR = NetTools.GetResponse(Dr["InvoiceUrl"].ToString());
                                                string pattern = @"(?=http).*(?<=\.pdf|.png)";
                                                Regex regex = new Regex(pattern);
                                                MatchCollection matches = regex.Matches(HTMLSTR);
                                                foreach (System.Text.RegularExpressions.Match match in matches)
                                                {
                                                    if (Path.GetExtension(match.Value).ToLower() == ".png")
                                                    {
                                                        FaPiaoImageUrl = match.Value;
                                                    }
                                                    else if (Path.GetExtension(match.Value).ToLower() == ".pdf")
                                                    {
                                                        FaPiaoUrl = match.Value;
                                                    }
                                                }

 

posted @ 2024-01-18 13:40  亦承  阅读(100)  评论(0)    收藏  举报