懒得勤快 7 年之前
父節點
當前提交
89252d91c3
共有 3 個文件被更改,包括 31 次插入6 次删除
  1. 15 3
      Masuit.Tools.Core/Html/HtmlHelper.cs
  2. 14 2
      Masuit.Tools/Html/HtmlHelper.cs
  3. 2 1
      Test/Program.cs

+ 15 - 3
Masuit.Tools.Core/Html/HtmlHelper.cs

@@ -8,7 +8,7 @@ using System.Threading;
 using System.Web;
 using Masuit.Tools.Win32;
 
-namespace Masuit.Tools.Html
+namespace Masuit.Tools.Core.Html
 {
     /// <summary>
     ///1、获取HTML<br/>
@@ -454,7 +454,13 @@ namespace Masuit.Tools.Html
         /// <returns></returns>
         public static string MatchFirstImgSrc(this string html)
         {
-            return Regex.Match(html, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^>]*>").Groups[1].Value;
+            string src = Regex.Match(html, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^>]*>").Groups[1].Value;
+            int index = src.IndexOf("\"", StringComparison.Ordinal);
+            if (index > 0)
+            {
+                src = src.Substring(0, index);
+            }
+            return src;
         }
 
         /// <summary>
@@ -467,7 +473,13 @@ namespace Masuit.Tools.Html
             MatchCollection collection = Regex.Matches(html, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^>]*>");
             if (collection.Count > 0)
             {
-                return collection[new Random().StrictNext(collection.Count)].Groups[1].Value;
+                string src = collection[new Random().StrictNext(collection.Count)].Groups[1].Value;
+                int index = src.IndexOf("\"", StringComparison.Ordinal);
+                if (index > 0)
+                {
+                    src = src.Substring(0, index);
+                }
+                return src;
             }
             return String.Empty;
         }

+ 14 - 2
Masuit.Tools/Html/HtmlHelper.cs

@@ -454,7 +454,13 @@ namespace Masuit.Tools.Html
         /// <returns></returns>
         public static string MatchFirstImgSrc(this string html)
         {
-            return Regex.Match(html, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^>]*>").Groups[1].Value;
+            string src = Regex.Match(html, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^>]*>").Groups[1].Value;
+            int index = src.IndexOf("\"", StringComparison.Ordinal);
+            if (index > 0)
+            {
+                src = src.Substring(0, index);
+            }
+            return src;
         }
 
         /// <summary>
@@ -467,7 +473,13 @@ namespace Masuit.Tools.Html
             MatchCollection collection = Regex.Matches(html, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^>]*>");
             if (collection.Count > 0)
             {
-                return collection[new Random().StrictNext(collection.Count)].Groups[1].Value;
+                string src = collection[new Random().StrictNext(collection.Count)].Groups[1].Value;
+                int index = src.IndexOf("\"", StringComparison.Ordinal);
+                if (index > 0)
+                {
+                    src = src.Substring(0, index);
+                }
+                return src;
             }
             return String.Empty;
         }

+ 2 - 1
Test/Program.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using Masuit.Tools;
 
 namespace Test
 {
@@ -84,7 +85,7 @@ namespace Test
             //LogManager.Error(typeof(object), "bbbbbbbbbbbbbbbbb");
             //LogManager.Info("aaaaaaaaaaaaaaaaaaaaaaaaa");
 
-
+            bool b = "[email protected]".MatchEmail();
             Console.ReadKey();
         }
     }