Esempio n. 1
0
        /// <summary>
        /// 获取首页超链接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void Zol_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                if (e.Result != null)
                {
                    #region 开启异步

                    string temp = "";
                    for (int i = 0; i < 4; i++)
                    {
                        switch (i)
                        {
                            case 0:
                                temp = "笔记本";
                                break;
                            case 1:
                                temp = "手机";
                                break;
                            case 2:
                                temp = "平板电脑";
                                break;
                            case 3:
                                temp = "数码相机";
                                break;
                        }
                        string regComputer2 = @"<a\s+href\s*=\s*[|']?(?<uri>[^'>]*)[|']?[^<>]*>\s*(<[^<>]+>)*(?<title>[^<>]*)(<[^<>]+>)*\s*" + temp + "</a>";
                        Regex r2 = new Regex(regComputer2);
                        MatchCollection match2 = r2.Matches(e.Result.ToString());
                        GetComputer(GetNewUrl(match2[0].ToString()), i);//此处传一个所属类别变量 0为电脑 1为手机 2为平板 3为数码相机
                    }
                    #endregion

                    #region 此处获取关于所有产品分类的子分类 如:手机 : 诺基亚 三星 苹果等 每项6个
                    MatchCollection match = Regex.Matches(e.Result.ToString(), @"】.*?【", RegexOptions.Singleline);
                    for (int i = 0; i < 4; i++)
                    {
                        string regComputer1 = @"<a\s+href\s*=\s*[|']?(?<uri>[^'>]*)[|']?[^<>]*>\s*(<[^<>]+>)*(?<title>[^<>]*)(<[^<>]+>)*\s*</a>";
                        Regex r1 = new Regex(regComputer1);
                        MatchCollection match1 = r1.Matches(match[i].ToString());//<a href=\"/list/57_98.html\">三星</a>
                        listComputerItemUrl = new List<ComputerItemUrl>();
                        foreach (var item in match1)
                        {
                            computerItemUrl = new ComputerItemUrl();
                            computerItemUrl.name = item.ToString().Split('>')[1].ToString().Replace("</a", "").Replace("&gt", "").Replace(";", "");//获取联想//&gt;
                            //根据联想到commonHelper类中获取图片
                            computerItemUrl.image = CommonHelper.GeImageUrlByName(computerItemUrl.name);
                            computerItemUrl.description = computerItemUrl.name;
                            computerItemUrl.url = GetNewUrl("<" + item.ToString().Split('<')[1].ToString());//获取联想对应的url
                            //保存到对应的对象中
                            listComputerItemUrl.Add(computerItemUrl);
                        }
                        switch (i)
                        {
                            case 0:
                                listComputerPhoneItemUrl = listComputerItemUrl;//手机
                                break;
                            case 1:
                                listComputerComputerItemUrl = listComputerItemUrl;//笔记本
                                break;
                            case 2:
                                listComputerCameraItemUrl = listComputerItemUrl;//此处先数码相机
                                break;
                            case 3:
                                listComputerTableComputerItemUrl = listComputerItemUrl;//后平板电脑
                                break;
                        }
                        if (listComputerItemUrl != null)
                        {
                            if (EventBindMainPageComputerDelegateHandler != null)
                            {
                                EventBindMainPageComputerDelegateHandler(i);//获取首页所有的超链接  包含笔记本首页/联想/三星/苹果/
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                    #endregion

                    #region 实例化四个要绑定的对象
                    listBindComputerDetail = new List<ComputerDetail>();
                    listBindPhoneDetail = new List<ComputerDetail>();
                    listBindTableComputerDetail = new List<ComputerDetail>();
                    listBindCameraDetail = new List<ComputerDetail>();
                    #endregion
                }
                else
                {
                    return;
                }
            }
            catch
            {
                return;
            }
        }
Esempio n. 2
0
 static void computerProduction_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
 {
     try
     {
         if (e.Result != null)
         {
             MatchCollection matchParam = Regex.Matches(e.Result.ToString(), "品牌列表</p>.*?</p>", RegexOptions.Singleline);
             //<br/>
             if (matchParam.Count > 0)
             {
                 string[] str = matchParam[0].ToString().Replace("<br/>", "◆").Split('◆');
                 listComputerOtherItemUrl = new List<ComputerItemUrl>();
                 for (int i = 0; i < str.Length - 1; i++)
                 {
                     string regComputer1 = @"<a\s+href\s*=\s*[|']?(?<uri>[^'>]*)[|']?[^<>]*>\s*(<[^<>]+>)*(?<title>[^<>]*)(<[^<>]+>)*\s*</a>";
                     Regex r1 = new Regex(regComputer1);
                     MatchCollection match1 = r1.Matches(str[i].ToString());//<a href=\"/list/57_98.html\">三星</a>
                     if (match1.Count > 0)
                     {
                         computerItemUrl = new ComputerItemUrl();
                         computerItemUrl.name = match1[0].ToString().Split('>')[1].ToString().Replace("</a", "");//获取联想;
                         //根据联想到commonHelper类中获取图片
                         computerItemUrl.image = CommonHelper.GeImageUrlByName(computerItemUrl.name);
                         computerItemUrl.url = GetNewUrl(str[i]);//获取联想对应的url
                         computerItemUrl.num = str[i].Split('(')[1].ToString().Replace(")", "");
                         computerItemUrl.description = computerItemUrl.num;
                         //\(\d*\) "";
                         //保存到对应的对象中
                         listComputerOtherItemUrl.Add(computerItemUrl);
                     }
                     else {
                         computerItemUrl = new ComputerItemUrl();
                         computerItemUrl.name ="暂无数据";//获取联想;
                         computerItemUrl.image ="image/404.jpg";
                         computerItemUrl.url ="暂无数据";//获取联想对应的url
                         computerItemUrl.num = "暂无数据";
                         computerItemUrl.description = "暂无数据";
                         listComputerOtherItemUrl.Add(computerItemUrl);
                     }
                 }
                 if (listComputerOtherItemUrl.Count > 0)
                 {
                     if (EventBindMainPage4ComputerParamDelegateHandler != null)
                     {
                         EventBindMainPage4ComputerParamDelegateHandler("right");
                     }
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 computerItemUrl = new ComputerItemUrl();
                 computerItemUrl.name = "暂无数据";//获取联想;
                 computerItemUrl.image = "image/404.jpg";
                 computerItemUrl.url = "暂无数据";//获取联想对应的url
                 computerItemUrl.num = "暂无数据";
                 computerItemUrl.description = "暂无数据";
                 listComputerOtherItemUrl.Add(computerItemUrl);
                 if (EventBindMainPage4ComputerParamDelegateHandler != null)
                 {
                     EventBindMainPage4ComputerParamDelegateHandler("error");
                 }
             }
         }
     }
     catch
     {
         return;
     }
 }