Himall商城Html文本帮助类HtmlContentHelper(2)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
1..取得HTML中所有圖片的 URL
/// <summary>
/// 取得HTML中所有圖片的 URL。
/// </summary>
/// <param name="htmlText">HTML代碼</param>
/// <returns>圖片的URL列表</returns>
static IEnumerable<string> GetHtmlImageUrlList(string htmlText)
{
// 定義正則表達式用來匹配 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(htmlText);
int i &#
總結
以上是生活随笔為你收集整理的Himall商城Html文本帮助类HtmlContentHelper(2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Sublime】使用 Sublime
- 下一篇: 【R】语言第五课----画图