QiFeng.ZWY.Utility/HtmlHelper.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace QiFeng.LMSD.Utility
{
public class HtmlsHelper
{
/// <summary>
/// 获取Html字符串中指定标签的指定属性的值
/// </summary>
/// <param name="html">Html字符</param>
/// <param name="tag">指定标签名</param>
/// <param name="attr">指定属性名</param>
/// <returns></returns>
public static List<string> GetHtmlAttr(string html, string tag, string attr)
{
// 定义正则表达式用来匹配 img 标签
Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
// 搜索匹配的字符串
MatchCollection matches = regImg.Matches(html);
int i = 0;
string[] sUrlList = new string[matches.Count];
// 取得匹配项列表
foreach (Match match in matches)
sUrlList[i++] = match.Groups["imgUrl"].Value;
return sUrlList.ToList();
}
/// <summary>
/// 获取HTML内容的制定标签列表
/// </summary>
/// <param name="html"></param>
/// <param name="tag"></param>
/// <returns></returns>
public static List<string> GetHtmlTag(string html, string tag)
{
//var result = new List<string>();
//Regex r = new Regex(@"/<(\"[^\"]*" | '[^'] * '|[^'">])*>/", RegexOptions.IgnoreCase);
//MatchCollection col = r.Matches(html);
//foreach (Match item in col)
// result.Add(item.Value);
//return result;
if (String.IsNullOrEmpty(html))
{
return null;
}
string regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
//html = Regex.(html, regEx_html, "");//删除html标记
后面还有 31 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。