/// <summary>
        
/// 得到下拉框的Options [列名:name,value]
        
/// </summary>
        
/// <param name="data">查找的数据</param>
        
/// <param name="Search">下拉框的 id 或 Name</param>
        
/// <returns>DataTable 列名:name,value</returns>
        public System.Web.UI.WebControls.ListItem[] GetOptions(string data, string Search)
        {
            
if (data.IndexOf(Search) == -1)
                
return null;
            
string options = null;
            Search 
= ReplaceChar(Search);

            
string pattern = @"(?<=<)select\s?(?:(?:name=[""']?" + Search + @"[""']?){1}|(?:[\w\W]+?id=[""']?" + Search + @"[""']?){1}){1}[^>]+>(?<option>[\w\W]+?)</select(?=>)";

            Regex r 
= new Regex(pattern, RegexOptions.IgnoreCase);
            MatchCollection mc 
= r.Matches(data);
            
if (mc.Count > 0)
                options 
= mc[0].Groups["option"].Value.Trim().Replace("&nbsp;""");
            
if (!string.IsNullOrEmpty(options))
            {
                pattern 
= @"(?<=<)option\s?.*value=[""']?(?<value>[^""']*)[^>]+>(?<name>[^<]+)</option(?=>)";

                r 
= new Regex(pattern, RegexOptions.IgnoreCase);
                mc 
= r.Matches(options);
                
if (mc.Count > 0)
                {
                    System.Web.UI.WebControls.ListItem[] li 
= new System.Web.UI.WebControls.ListItem[mc.Count];
                    
int i = 0;
                    
foreach (Match m in mc)
                    {
                        li[i] 
= new System.Web.UI.WebControls.ListItem(m.Groups["name"].Value, m.Groups["value"].Value);
                        i
++;
                    }
                    
return li;
                }
            }
            
return null;
        }

 

使用示例:

 

//因为数据太多,所以就给个数据地址,打个比方
string data = "";//http://pay.wanmei.com/e/jsp/setup_3_yikatong.jsp?gametype=3 这个页面的源代码
//因为这个页面里面有个 name为zoneid_3的下拉框,所以可以用下面的方法提取并绑定
DropArea.Items.AddRange(Common.StringPro.TheInstance.GetOptions(data, "zoneid_3"));