static void TestT() { var source = WebTool.GetHtmlAsyncUtf8("http://www.mobile01.com/topicdetail.php?f=568&t=3299999"); string aid = null; string aowner = null; string forum = null; TmpUser = new Dictionary <string, string>(); source = WebTool.GetContent("<div class=\"forum-content\">", "<div class=\"sidebar\">", source); //Get Title var title = WebTool.GetContent("<h2 class=\"topic\">", "</h2>", source); //Get Page var page = WebTool.GetContent("<p class=\"numbers\">", "</p>", source); //process post -begin- source = WebTool.GetContent("<div class=\"single-post\">", "<div class=\"pagination\">", source); var ar = source.Split(new[] { "<div class=\"single-post\">" }, StringSplitOptions.RemoveEmptyEntries); //Get all foreach (var s in ar) { ProcessPost(s, ref aid, ref aowner, forum, title); } }
static void TestP() //get date and replay { var source = WebTool.GetHtmlAsyncUtf8("http://www.mobile01.com/forumtopic.php?c=16&s=20"); source = WebTool.GetContent("<table summary=\"文章列表\">", "</table>", source); source = WebTool.GetContent("<tbody>", "</tbody>", source).Replace("\n", string.Empty); //topic list var arTopic = source.Split(new[] { "<tr>" }, StringSplitOptions.RemoveEmptyEntries); arTopic = arTopic.Where(x => x.Trim().Length > 10).ToArray(); foreach (var s in arTopic) { var reply = WebTool.GetContent("<td width=\"7%\" class=\"reply\">", "</td>", s).Replace(",", string.Empty); var postDate = Convert.ToDateTime(WebTool.StripTagsCharArray(WebTool.GetContent("<td width=\"17%\" class=\"authur\">", "</p>", s))); var url = WebTool.GetContent("<td class=\"subject\">", "</a>", s); var topicUrl = WebTool.GetContent("<a href=\"", "\"", url); var topicTitle = WebTool.StripTagsCharArray((url.Split(new[] { "</td>" }, StringSplitOptions.RemoveEmptyEntries)[0])).Trim(); Console.WriteLine("topicUrl=" + topicUrl + "\ntopicTitle=" + HttpUtility.HtmlDecode(topicTitle) + "\nreply=" + reply + "\ndate=" + postDate); if (postDate > Convert.ToDateTime("2013-03-15")) { Console.WriteLine("Date over 2013-03-15" + postDate); } } }
static void ProcessPost(string post, ref string levelOneUid, ref string levelOnePid, string forum, string title) { var uid = WebTool.GetContent("userinfo.php?id=", "&", post); var uName = WebTool.StripTagsCharArray(WebTool.GetContent("<div class=\"fn\">", "</div>", post)); var content = WebTool.GetContent("<div class=\"single-post-content\">", "<div class=\"single-post-content-sig\">", post); var pid = WebTool.GetContent("<div id=\"ct", "\"", post); var tmpar = WebTool.GetContent("<div class=\"date\">", "</div>", post).Split('#'); var pdate = tmpar[0].Trim(); var plevel = tmpar[1].Trim(); var aid = string.Empty; var aowner = string.Empty; var blockquite = WebTool.GetContent("<blockquote>", "</blockquote>", post); var replyTo = WebTool.GetContent("<b>", " wrote:</b>", blockquite); Console.WriteLine(TmpUser == null); if (!TmpUser.ContainsKey(uName)) { TmpUser.Add(uName, uid); } Console.WriteLine("pid=" + pid + " uid=" + uid + " name=" + uName); //if (!string.IsNullOrEmpty(replyTo)) Console.WriteLine("\tblockquote=" + replyTo); if (plevel == "1") { levelOnePid = pid; levelOneUid = uid; } else { aid = levelOnePid; aowner = levelOneUid; //add counter if (string.IsNullOrEmpty(replyTo)) { //ThriftTool.CounterAdd(uid, "M01UserRelaction", levelOneUid, 1); } else { Console.WriteLine("\tblockquote=" + TmpUser[replyTo]); } // } var topic = new M01Topic { Forum = forum, Pid = pid, Uid = uid, Content = content, Pdate = pdate, Plevel = plevel, Aid = aid, Aowner = aowner, Title = title }; //if (blockquite != null) //SaveTopic(topic); }