示例#1
0
        public static string GetKeywords(string urls)
        {
            Uri        uri;
            KeySearchs kss = GetKeySearch();
            string     ie  = "";
            string     key = string.Empty;

            try { uri = new Uri(urls); }
            catch { return(string.Empty); }
            string host = uri.Host.ToLower();

            foreach (KeySearch ks in kss)
            {
                if (host.IndexOf(ks.SUrl) != -1)
                {
                    if (!string.IsNullOrEmpty(ks.Ei))
                    {
                        ie = Util.GetRequestUrl(ks.Ei, urls);
                    }
                    if (ie == "")
                    {
                        ie = ks.Ie;
                    }
                    string[] spk = ks.SKey.Split(new char[] { '|' });
                    for (int i = 0; i < spk.Length; i++)
                    {
                        key = Util.GetRequestUrl(spk[i], urls);
                        if (key.Trim().Length > 0)
                        {
                            break;
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(ie))
            {
                if (ie.ToLower().IndexOf("gb") != -1)
                {
                    ie = "gb2312";
                }
                if (ie.ToLower().IndexOf("utf") != -1)
                {
                    ie = "utf-8";
                }
                key = HttpUtility.UrlDecode(key, System.Text.Encoding.GetEncoding(ie));
            }
            return(key);
        }
示例#2
0
        /// <summary>
        /// 获取所有的搜索引擎
        /// </summary>
        public static KeySearchs GetKeySearch()
        {
            KeySearchs kss = new KeySearchs();

            using (DataSet ds = Logic.Consult.GetKeySearch())
            {
                if (Common.Util.CheckDataSet(ds))
                {
                    foreach (DataRow reader in ds.Tables[0].Rows)
                    {
                        KeySearch ks = new KeySearch();
                        ks.Id    = Util.ConvertToInt(reader["id"].ToString());
                        ks.SName = reader["sname"].ToString();
                        ks.SUrl  = reader["surl"].ToString();
                        ks.Ie    = reader["ie"].ToString();
                        ks.SKey  = reader["skey"].ToString();
                        kss.Add(ks);
                    }
                    return(kss);
                }
            }
            return(null);
        }