正则解析HTML中的IMG中的图片地址

ContractedBlock.gif ExpandedBlockStart.gif Code
 1 using System;
 2 
 3 using System.Collections.Generic;
 4 
 5 using System.Text;
 6 
 7 using System.Text.RegularExpressions;
 8 
 9 using System.IO;
10 
11 using System.Net;
12 
13  
14 
15 namespace imgtest
16 
17 {
18 
19     class Program
20 
21     {
22 
23         static void Main(string[] args)
24 
25         {
26 
27             string PageText = "<TABLE cellSpacing=0 cellPadding=0 width=1000 border=0>  <TBODY>  <TR>  <TD width=859><img id=index_cut_r1_c1 height=67 alt=\"\" src=\"http://www.cneeex.com/images/index_cut_r1_c1.gif\" width=859 border=0 name=index_cut_r1_c1></TD>  <TD width=63><IMG id=index_cut_r1_c16 height=67 alt=\"\" src=\"http://www.cneeex.com/images/index_cut_r1_c16.gif\" width=63 border=0 name=index_cut_r1_c16></TD> ";
28 
29             PageText = PageText.Replace("\r\n""");
30 
31             MatchCollection TDMatchs = Regex.Matches(PageText, "<IMG.*?src=\"(.*?.*?)\".*?>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
32 
33             for (int i = 0; i < TDMatchs.Count; i++)
34 
35             {
36 
37                 Console.WriteLine("图片地址为:" + TDMatchs[0].Groups[1].Value);
38 
39             }
40 
41             Console.Read();
42 
43         }
44 
45     }
46 
47 }
48 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值