从<div id="productDescription" class="productGeneral biggerText"><h3>Description:</h3>
<p>2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get one in our online store!</p>
<h3>Features:</h3>
<ul>
<li>Color:As picture</li>
<li>Size: W32 cm X H29 cm X D17 cm</li>
</ul>
<h3>Details:</h3>
<ul>
<li>Side laces to change the shape of the bag</li>
<li>Red textile linning</li>
<li>Leather trimmings</li>
<li>Large interior zipped pocket which can fit a long wallet</li>
<li>Interior D-ring for keys and an accessory<li>
<li>Metallic pieces in shiny golden brass</li>
</ul></div>
这段代码中 获取
2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get one in our online store!As pictureW32 cm X H29 cm X D17 cmSide laces to change the shape of the bagRed textile linning
Leather trimmings
Large interior zipped pocket which can fit a long wallet
Interior D-ring for keys and an accessory
Metallic pieces in shiny golden brass跪求大神帮忙
<p>2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get one in our online store!</p>
<h3>Features:</h3>
<ul>
<li>Color:As picture</li>
<li>Size: W32 cm X H29 cm X D17 cm</li>
</ul>
<h3>Details:</h3>
<ul>
<li>Side laces to change the shape of the bag</li>
<li>Red textile linning</li>
<li>Leather trimmings</li>
<li>Large interior zipped pocket which can fit a long wallet</li>
<li>Interior D-ring for keys and an accessory<li>
<li>Metallic pieces in shiny golden brass</li>
</ul></div>
这段代码中 获取
2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get one in our online store!As pictureW32 cm X H29 cm X D17 cmSide laces to change the shape of the bagRed textile linning
Leather trimmings
Large interior zipped pocket which can fit a long wallet
Interior D-ring for keys and an accessory
Metallic pieces in shiny golden brass跪求大神帮忙
解决方案 »
- winform 动态生成的 DataGridView 添加行 如何有默认值?
- C# 如何实现圆角无边窗体?急救
- rdlc报表数据源问题
- C#加法运算
- 它ResponseEncoding="GB2312"必须用,但使用的话,在页面中的文本框中输入文字,再点击按钮搜索,就会出错,文本框中的文字就会编程乱码
- 多线程 MessageBox.Show()问题
- 怎样才能使系统不把双击当成两个单击+双击?
- 用VS2010连接SQLEXPRESS 2008时出现“未将对象引用设置到对象的实例。”,怎么解决
- 这就是传说中的内存泄露吗?
- 关于字符串分割的问题
- 递归造成的 “System.StackOverflowException”类型的异常
- 请问:如何获得axWindowsMediaPlayer当前播放歌曲的url?
// html 就是输入字符串
StringBuilder sb = new StringBuilder();
foreach(Match m in Regex.Matches(html, @"<([^>]+)>([^<]*)</[^>]+>")) {
if(m.Groups[1].Value == "p") {
sb.Append(m.Groups[2].Value);
sb.Append('\n');
} else if(m.Groups[1].Value == "li") {
string value = m.Groups[2].Value;
int idx = value.IndexOf(':');
if(idx != -1) value = value.Substring(idx + 1);
sb.Append(value);
sb.Append('\n');
}
}
Console.WriteLine(sb);
StreamReader sr = new StreamReader(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));
string tempStr =sr.ReadToEnd();
string pattern = @"<(li|p)[^>]*>([^<]+:)*([^<]+)</(li|p)>";
MatchCollection mc = Regex.Matches(tempStr, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
foreach (Match m in mc)
{
string tempValue = m.Value;
string text = m.Groups[3].Value;//循环输出内容
}
void Main()
{
string str = @"<div id=""productDescription"" class=""productGeneral biggerText""><h3>Description:</h3>
<p>2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get one in our online store!</p>
<h3>Features:</h3>
<ul>
<li>Color:As picture</li>
<li>Size: W32 cm X H29 cm X D17 cm</li>
</ul>
<h3>Details:</h3>
<ul>
<li>Side laces to change the shape of the bag</li>
<li>Red textile linning</li>
<li>Leather trimmings</li>
<li>Large interior zipped pocket which can fit a long wallet</li>
<li>Interior D-ring for keys and an accessory<li>
<li>Metallic pieces in shiny golden brass</li>
</ul></div>";
foreach(Match m in Regex.Matches(str,@"(?is)(?<=<(p|li)>).*?(?=</?\1>)"))
{
Console.WriteLine((m.Value.Contains("Color:")||m.Value.Contains("Size:"))?m.Value.Split(':')[1]:m.Value);
}
/*
2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get one in our online store!
As picture
W32 cm X H29 cm X D17 cm
Side laces to change the shape of the bag
Red textile linning
Leather trimmings
Large interior zipped pocket which can fit a long wallet
Interior D-ring for keys and an accessory
Metallic pieces in shiny golden brass */
}
eof Main Product Image--><!--bof Product Name--><h1 id="productName" class="productGeneral">Louis Vuitton Monogram Canvas Delightful PM MM M40352</h1><!--eof Product Name--><div id="stylebags_pro_model">Model: M40352</div><!--bof Product Price block --><h2 id="productPrices" class="productGeneral"><span class="normalprice">$299.00 </span> <span class="productSpecialPrice">$209.00</span></h2><!--
这当中获取
Louis Vuitton Monogram Canvas Delightful PM MM M40352M40352$209.00
最后一个问题了 拜托大神了
Regex re = new Regex("<h1 id=\"productName\" class=\"productGeneral\">([^<]*)</h1>.*Model:([^<]*)</div>.*<span class=\"productSpecialPrice\">([^<]*)</span>");
foreach (Match s in re.Matches(test))
{
Console.WriteLine(s.Groups[1].Value.ToString().Trim());
Console.WriteLine(s.Groups[2].Value.ToString().Trim());
Console.WriteLine(s.Groups[3].Value.ToString().Trim());
}
{
Response.Write(m.Groups[2].Value+"<br/>");
}
/*
Louis Vuitton Monogram Canvas Delightful PM MM M40352
M40352
$299.00
$209.00
*/
Regex reg = new Regex(@"(?i)<h1\s*?id=.productName[^>]*?>([^<]*?)</h1>[^;]*?;<span\s*?class=.productSpecialPrice[^>]*?>([^<]*?)</span>"); MatchCollection mc = reg.Matches(test);
String[] number = null;
foreach (Match m in mc)
{
number = m.Groups[1].Value.Split(' ');
Console.WriteLine(m.Groups[1].Value);
Console.WriteLine(number[number.Length-1]);
Console.WriteLine(m.Groups[2].Value);
}/*输出
Louis Vuitton Monogram Canvas Delightful PM MM M40352
M40352
$209.00*/
StreamReader sr = new StreamReader(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));
string tempStr =sr.ReadToEnd();
string pattern = @"(?m)(?<=<(h1|div|span)[^>]*>)([^<]+:)*([^<]+)(?=</?\1>)";
MatchCollection mc = Regex.Matches(tempStr, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
foreach (Match m in mc)
{
if (!string.IsNullOrEmpty(m.Groups[3].Value))
{
//循环输出内容
Console.WriteLine(m.Groups[3].Value);
}
}
请各位大神 来这里
http://topic.csdn.net/u/20111101/13/7958f503-ec6c-43b4-857a-a62e81039ad7.html
继续接分