private void Parse(Object sendor, OnCompletedEventArgs args)
        {
            lock (lock1)
            {
                Count++;
                Answer_ZHIHU answer = new Answer_ZHIHU();
                try
                {
                    String          strRef  = @"{""id""[\s|\S]+?""upvoted_followees"":";
                    MatchCollection matches = new Regex(strRef).Matches(args.PageSource);
                    strRef       = @"title"":""[\s|\S]+?""";
                    answer.Title = new Regex(strRef).Match(matches[0].Value).Value.Substring(7).Trim('"');
                    strRef       = @"url"":""[\s|\S]+?""";
                    answer.Url   = new Regex(strRef).Match(matches[0].Value).Value.Substring(5).Trim('"');
                    answer.Url   = Regex.Replace(answer.Url, @"\/api\/v4\/questions", @"/question");

                    String author, content, voteUp;
                    answer.List = new List <AnswerDetail>();
                    foreach (Match match in matches)
                    {
                        author  = new Regex(@"name"":""[\s|\S]+?""").Match(match.Value).Value.Substring(7).Trim('"');
                        voteUp  = new Regex(@"voteup_count"":[0-9]+?,").Match(match.Value).Value.Substring(14).Trim(',');
                        content = new Regex(@"content"":""[\s|\S]+?"",""").Match(match.Value).Value.Substring(10).Trim('"', ',');
                        content = Regex.Replace(content, @"\\u003c[\s|\S]+?\\u003e", "");
                        answer.List.Add(new AnswerDetail(content, author, Convert.ToInt32(voteUp)));
                    }
                    AnswerList.Add(answer);
                    multiSpider.GetFunc(new Uri(answer.Url)).Wait();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Esempio n. 2
0
        //private List<Win_ZHIHU_Response> answers;

        /// <summary>
        ///
        /// </summary>
        /// <param name="answer"></param>
        public Win_ZHIHU_ANSWER(Answer_ZHIHU answer)
        {
            this.AutoSize    = true;
            this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.Location    = new System.Drawing.Point(3, 3);
            this.Size        = new System.Drawing.Size(760, 236);
            this.TabIndex    = 3;
            this.MinimumSize = new System.Drawing.Size(760, 0);
            headPanel        = new Win_ZHIHU_HeadPanel(answer.Title, answer.MultiLine, answer.Url);
            for (int i = answer.List.Count - 1; i >= 0; i--)
            {
                this.Controls.Add(new Win_ZHIHU_Response(answer.List[i]));
            }
            this.Controls.Add(headPanel);
        }