获取 下面内容
家用电器
手机数码
电脑产品
日用百货
<ul id="Nav">
<li ><span class="Nav_first"><a href="http://www.360buy.com/" onclick="setWebBILinkCount('index_channel_index')" onfocus="this.blur()">首 页</a></span></li>
<li ><span><a href="http://www.360buy.com/electronic.html" onclick="setWebBILinkCount('index_channel_ele')" onfocus="this.blur()">家用电器</a></span></li>
<li ><span><a href="http://www.360buy.com/digital.html" onclick="setWebBILinkCount('index_channel_mobile')" onfocus="this.blur()">手机数码</a></span></li>
<li class="curr"><span><a href="http://www.360buy.com/computer.html" onclick="setWebBILinkCount('index_channel_pc')" onfocus="this.blur()">电脑产品</a></span></li>
<li ><span><a href="http://www.360buy.com/jdlife.html" onclick="setWebBILinkCount('index_channel_jdlife')" onfocus="this.blur()">日用百货</a></span></li>
</ul>
家用电器
手机数码
电脑产品
日用百货
<ul id="Nav">
<li ><span class="Nav_first"><a href="http://www.360buy.com/" onclick="setWebBILinkCount('index_channel_index')" onfocus="this.blur()">首 页</a></span></li>
<li ><span><a href="http://www.360buy.com/electronic.html" onclick="setWebBILinkCount('index_channel_ele')" onfocus="this.blur()">家用电器</a></span></li>
<li ><span><a href="http://www.360buy.com/digital.html" onclick="setWebBILinkCount('index_channel_mobile')" onfocus="this.blur()">手机数码</a></span></li>
<li class="curr"><span><a href="http://www.360buy.com/computer.html" onclick="setWebBILinkCount('index_channel_pc')" onfocus="this.blur()">电脑产品</a></span></li>
<li ><span><a href="http://www.360buy.com/jdlife.html" onclick="setWebBILinkCount('index_channel_jdlife')" onfocus="this.blur()">日用百货</a></span></li>
</ul>
<li > <span> <a href="http://www.360buy.com/electronic.html" onclick="setWebBILinkCount('index_channel_ele')" onfocus="this.blur()">家用电器 </a> </span> </li>
string s = "<li > <span> <a href=\"http://www.360buy.com/electronic.html\" onclick=\"setWebBILinkCount('index_channel_ele')\" onfocus=\"this.blur()\">家用电器 </a> </span> </li>"
Regex rg = new Regex("<li > <span> <a .+>(\\w+) </a> </span> </li>");
bool b = rg.IsMatch(s);//我測試時,這裡返回true
Match m = rg.Match(s); string name = m.Groups[1];//這裡取出的值就是你想要的值了,這裡在正則表達式中就是我用()括起來的那個地方的值
//Regex 類在這個命名空間中哦
using System.Text.RegularExpressions;
這句改下。。我的運行結果你看看呢m.Groups[1] {家用电器}
b true bool
rg {<li > <span> <a .+>(\w+) </a> </span> </li>}
s "<li > <span> <a href=\"http://www.360buy.com/electronic.html\" onclick=\"setWebBILinkCount('index_channel_ele')\" onfocus=\"this.blur()\">家用电器 </a> </span> </li>" 圖貼不上哦 不貼了
要获取 求求大家了!!!!! 我没分发贴了
(1) 电脑整机首页
(2)电脑整机
(3)笔记本
(4)联想
<div id="Position" class="margin_b6"><a href="http://www.360buy.com/">首页</a> > <a href = "http://www.360buy.com/computer.aspx">电脑整机首页</a> > <a href="http://www.360buy.com/products/670-671-000-0-0-0-0-0-0-0-1-1-1.html">电脑整机</a> > <a href="http://www.360buy.com/products/670-671-672-0-0-0-0-0-0-0-1-1-1.html">笔记本</a> > <a href="http://www.360buy.com/brands/672,%e8%81%94%e6%83%b3.html">联想</a></div>
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;namespace FormExport
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string s = "<li > <span> <a href=\"http://www.360buy.com/electronic.html\" onclick=\"setWebBILinkCount('index_channel_ele')\" onfocus=\"this.blur()\">家用电器 </a> </span> </li>";
Regex rg = new Regex("<li > <span> <a .+>(\\w+) </a> </span> </li>");
bool b1 = Regex.IsMatch("asdf", ".*");
bool b = rg.IsMatch(s);
Match m = rg.Match(s); string name = m.Groups[1].ToString();
}
}
}回去睡覺了