已用HttpWebRequest读取网页的原始数据了,
但是要怎样获得某一特定的字符串呢?正则表不会写….求助!!
我想得到标签 “ nowrap> “ 开始到 ”</td>” 里面的的数字,显示到Winfrom
textBox1, textBox2, textBox3, textBox4
例:
……………… <td align="center" bgcolor="#FFFfff" nowrap>10:30</td>
<td align="center" bgcolor="#FFFfff" nowrap><b>11:40</b></td>
<td align="center" bgcolor="#FFFfff" nowrap>12.30</td>
<td align="center" bgcolor="#FFFfff" nowrap>13.45</td>………………………………………
但是要怎样获得某一特定的字符串呢?正则表不会写….求助!!
我想得到标签 “ nowrap> “ 开始到 ”</td>” 里面的的数字,显示到Winfrom
textBox1, textBox2, textBox3, textBox4
例:
……………… <td align="center" bgcolor="#FFFfff" nowrap>10:30</td>
<td align="center" bgcolor="#FFFfff" nowrap><b>11:40</b></td>
<td align="center" bgcolor="#FFFfff" nowrap>12.30</td>
<td align="center" bgcolor="#FFFfff" nowrap>13.45</td>………………………………………
或(?is)(?<=<td[^>]*>)(?:(?!</?td\b).)*(?=</td>)
MatchCollection mc1= reg1.Matches(str);
foreach (Match m1 in mc1)
{
Console.Write(m1.Groups[1].Value + m1.Groups[2].Value + m1.Groups[3].Value) ;
}
http://topic.csdn.net/u/20090722/21/c4812ab1-f659-49c2-99e4-617148121720.html?seed=1342860916&r=58555958
取到6筆~遺失一筆"<font color=#ff0000>△0.55" 為什麼??---Html Data---
<td align="center" bgcolor="#FFFfff" nowrap>10:30</td>
<td align="center" bgcolor="#FFFfff" nowrap><b>17.50</b></td>
<td align="center" bgcolor="#FFFfff" nowrap>17.45</td>
<td align="center" bgcolor="#FFFfff" nowrap>17.50</td>
<td align="center" bgcolor="#FFFfff" nowrap><font color=#ff0000>△0.55
<td align="center" bgcolor="#FFFfff" nowrap>21,576</td>
<td align="center" bgcolor="#FFFfff" nowrap>16.95</td>
<td align="center" bgcolor="#FFFfff" nowrap> <font color=#ff0000>△0.55那要怎麼樣也可以得到這一筆資料呢?
"<[^>]*>[^\.0-9]*?(?<number>[\.0-9]+).*?"取number里的数字
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO;
using System.Data.SqlClient;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = @"<td align=""center"" bgcolor=""#FFFfff"" nowrap>10:30 </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap> <b>17.50 </b> </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap>17.45 </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap>17.50 </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap> <font color=#ff0000>△0.55
<td align=""center"" bgcolor=""#FFFfff"" nowrap>21,576 </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap>16.95 </td>
";
Regex re = new Regex(@"(<[^>]+>)*[^\.0-9:,]*(?<number>[\.0-9:,]+).*?");
MatchCollection mc = re.Matches(str);
foreach(Match m in mc)
Console.WriteLine(m.Groups["number"].Value); }
}
}
奇怪,多了一个
10:30
17.50
17.45
17.50
0000
0.55
21,576
16.95
Press any key to continue . . .
<td align=""center"" bgcolor=""#FFFfff"" nowrap> <b>17.50 </b> </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap>17.45 </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap>17.50 </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap> <font color=#ff0000>△0.55
<td align=""center"" bgcolor=""#FFFfff"" nowrap>21,576 </td>
<td align=""center"" bgcolor=""#FFFfff"" nowrap>16.95 </td>";
Regex reg = new Regex(@"(?i)(?<=nowrap>).*?(?=</td>)");
MatchCollection mc = reg.Matches(html);
Console.WriteLine("/*\n------输出结果------------");
foreach (Match m in mc)
{
Console.WriteLine(m.Groups[0].ToString());
}
Console.WriteLine("*/"); /*
------输出结果------------
10:30
<b>17.50 </b>
17.45
17.50
21,576
16.95
*/