Beispiel #1
0
        public void Showad()
        {
            string pageHtml;

            try
            {
                WebClient MyWebClient = new WebClient();

                MyWebClient.Credentials = CredentialCache.DefaultCredentials;                          //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。

                byte[] pageData = MyWebClient.DownloadData("http://bbs.luobotou.org/app/wintogo.txt"); //从指定网站下载数据
                //MyWebClient.DownloadString()
                pageHtml = Encoding.UTF8.GetString(pageData);
                int index    = pageHtml.IndexOf("announcement=");
                int indexbbs = pageHtml.IndexOf("bbs=");
                if (pageHtml.Substring(index + 13, 1) != "0" && MsgManager.ci.EnglishName != "English")
                {
                    if (pageHtml.Substring(indexbbs + 4, 1) == "1")
                    {
                        //string pageHtml;
                        //WebClient MyWebClient2 = new WebClient();
                        MyWebClient.Credentials = CredentialCache.DefaultCredentials;                      //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。
                        byte[] pageData1 = MyWebClient.DownloadData("http://bbs.luobotou.org/portal.php"); //从指定网站下载数据
                        pageHtml = Encoding.UTF8.GetString(pageData1);

                        #region 正则表达式实现

                        Match           matchArticles = Regex.Match(pageHtml, @"<ul><li><a href=[\W\w]+?</li></ul>");
                        MatchCollection matches       = Regex.Matches(matchArticles.Groups[0].Value, @"<li><a href=""(.+?)"".+?>(.+?)</a></li>");

                        for (int i = 0; i < matches.Count; i++)
                        {
                            TopicLink[i] = matches[i].Groups[1].Value;
                            TopicName[i] = matches[i].Groups[2].Value;
                        }
                        #endregion



                        //int index1 = pageHtml.IndexOf("<ul><li><a href=");
                        //for (int i = 0; i < 10; i++)
                        //{

                        //    int LinkStartIndex = pageHtml.IndexOf("<li><a href=", index1) + 13;
                        //    int LinkEndIndex = pageHtml.IndexOf("\"", LinkStartIndex);
                        //    int TitleStartIndex = pageHtml.IndexOf("title=", LinkEndIndex) + 7;
                        //    int TitleEndIndex = pageHtml.IndexOf("\"", TitleStartIndex);
                        //    topicLink[i] = pageHtml.Substring(LinkStartIndex, LinkEndIndex - LinkStartIndex);
                        //    topicName[i] = pageHtml.Substring(TitleStartIndex, TitleEndIndex - TitleStartIndex);
                        //    index1 = LinkEndIndex;
                        //    //topicstring
                        //    //int adprogram = index1 + Application.ProductName.Length + 1;
                        //}
                    }
                    //string pageHtml1;
                    //WebClient MyWebClient1 = new WebClient();
                    //MyWebClient1.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。
                    //MyWebClient1.Encoding = Encoding.UTF8;
                    pageHtml = MyWebClient.DownloadString("http://bbs.luobotou.org/app/announcement.txt");
                    Match  match   = Regex.Match(pageHtml, Application.ProductName + "=(.+)~(.+)结束");
                    string adlink  = match.Groups[2].Value;
                    string adtitle = match.Groups[1].Value;
                    linkLabel.Invoke(new Action(() =>
                    {
                        linkLabel.Text    = adtitle;
                        linkLabel.Visible = true;
                    }));
                    linkLabel.Tag = adlink;
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog("ShowAdError.log", ex.ToString());
            }
        }