Пример #1
0
        /// <summary>
        /// 查询排名函数处理
        /// </summary>
        public void SearchSiteMutil()
        {
            string result = string.Empty;

            string[]      html    = null;
            int           ranknum = 0;
            List <string> alist   = new List <string>();

            MyDelegate d = new MyDelegate(UpdateText);

            //保留列的定义,清空所有的DT数据
            dt.Clear();

            DataRow dr;

            /************************增加代码在查询结果中也获取关键字的结果数********************/
            int    num       = 0;
            string strResult = string.Empty;
            string temp      = string.Empty;

            /************************************************************************************/

            this.Invoke(d, string.Format("共导入{0}结果!\r\n", urlKeywords.Count));

            for (int i = 0; i < urlKeywords.Count; i++)
            {
                //获得关键词源代码
                html = HtmlOpear.GetWebClient(GetStrURI(urlKeywords[i].KeyWords));

                if (html[0] == "false")
                {
                    this.Invoke(d, "\r\nIP被封!\r\n");
                    break;
                }

                ////////////////计算关键字的结果数量//////////////
                temp = Tools.Google_getProductNum(html[1]);

                num = (temp == string.Empty ? 0 : Convert.ToInt32(temp));

                if (num == 0)
                {
                    strResult = "没有收录";
                }
                else
                {
                    //插入逗号处理
                    strResult = Tools.InserChar(num.ToString());
                }
                /////////////////////////////////////////////////

                alist.Clear();//清空所有元素
                alist = GetUrlList(html[1]);

                result  = "\r\n第" + (i + 1) + "条 域名:" + urlKeywords[i].URL + "关键字:" + urlKeywords[i].KeyWords + "\r\n";
                result += Computingrankings(alist, urlKeywords[i].URL, out ranknum);

                dr = dt.NewRow();

                if (optionList.Contains("域名"))
                {
                    dr["域名"] = urlKeywords[i].URL;
                }

                if (optionList.Contains("关键词"))
                {
                    dr["关键词"] = urlKeywords[i].KeyWords;
                }
                if (optionList.Contains("结果数"))
                {
                    dr["结果数"] = strResult;
                }
                if (optionList.Contains("当前排名"))
                {
                    dr["当前排名"] = ranknum;
                }
                if (optionList.Contains("收录情况"))
                {
                    dr["收录情况"] = result;//对结果进一步的处理
                }
                dt.Rows.Add(dr);

                this.Invoke(d, result);

                //让当前的线程歇一会
                if (th != null)
                {
                    this.Invoke(d, "\r\n我在休息中...\r\n*************************************************************************\r\n");
                    th.Join(GetRandomSeconds());
                }
            }
            this.Invoke(d, "\r\n已处理完毕!\r\n");
        }
Пример #2
0
        /// <summary>
        /// 批量查询关键字
        /// </summary>
        public void SearchKeyMutil()
        {
            if (comListitem == null || comListitem.Count <= 0)
            {
                return;
            }

            //委托一个方法用来更新界面
            MyDelegate d = new MyDelegate(UpdateText);

            this.txtResult.Text = "";

            string strURI    = string.Empty;
            int    num       = 0;
            string strResult = string.Empty;
            string temp      = string.Empty;
            string result    = string.Empty;

            string[] html = null;

            this.Invoke(d, string.Format("共导入{0}结果!\r\n", comListitem.Count));

            DataRow dr;

            for (int i = 0; i < comListitem.Count; i++)
            {
                //组合关键的查询的URL 并对关键字中的空格进行处理
                strURI = this.strGoogleUrl + Tools.GetString(comListitem[i].ToString());

                html = HtmlOpear.GetWebClient(strURI);
                if (html[0] == "false")
                {
                    this.Invoke(d, "\r\nIP被封!\r\n");
                    break;
                }
                temp = Tools.Google_getProductNum(html[1]);

                num = (temp == string.Empty ? 0 : Convert.ToInt32(temp));

                if (num == 0)
                {
                    strResult = "没有收录";
                }
                else
                {
                    strResult = num.ToString();
                }

                //需要根据一个全局变量动态的构建
                dr = dt.NewRow();
                if (optionList.Contains("关键词"))
                {
                    dr["关键词"] = comListitem[i].ToString();
                }
                if (optionList.Contains("结果数"))
                {
                    dr["结果数"] = strResult;
                }

                dt.Rows.Add(dr);
                result = string.Format("\r\n第{0}条 {1}\t-结果数:\t{2}", i + 1, comListitem[i].ToString().PadRight(25, ' '), strResult + Environment.NewLine);
                this.Invoke(d, result);

                //让当前的线程歇一会
                if (th != null)
                {
                    this.Invoke(d, "\r\n我在休息中...\r\n");
                    th.Join(GetRandomSeconds());
                }
            }
            this.Invoke(d, "\r\n已处理完毕!\r\n");
        }