private Prize CreatePrizeFromDom(IDomObject prizeDom) { var prize = new Prize(); var dom = prizeDom.Cq().Select("span.prize-name").FirstOrDefault(); if (dom == null) { throw new Exception("Unable to find prize element 'span.prize-name'"); } prize.Name = dom.InnerText; dom = prizeDom.Cq().Select("div.multiplier-text").FirstOrDefault(); if (dom == null) { throw new Exception("Unable to find prize element 'span.prize-name'"); } prize.Quantity = int.Parse(dom.InnerText); dom = prizeDom.Cq().Select("img.icon").FirstOrDefault(); prize.ImageUrl = dom.GetAttribute("src"); return(prize); }
public string GetUrl(IDomObject trElement) { var list = trElement.Cq().Children("td").ToList(); var html = list[3].FirstElementChild.GetAttribute("href"); return("https://sv36.tribalwars.se" + html); }
public override bool Matches(IDomObject element) { switch (Mode) { case Modes.Attr: return Expression.IsMatch(element[Property] ?? ""); case Modes.Css: return Expression.IsMatch(element.Style[Property] ?? ""); case Modes.Data: return Expression.IsMatch(element.Cq().DataRaw(Property) ?? ""); default: throw new NotImplementedException(); } }
private static ThreadHeader GetThreadHeader(IDomObject titleNode, IDomObject authorNode, MillRequest request, int i) { var titleAnchor = titleNode.Cq().Find("a:first").FirstOrDefault(); if (titleAnchor == null) { throw new ProcessFaultException(request, string.Format("第{0}个title元素里面没有a元素。", i)); } var url = titleAnchor["href"]; var titleText = titleAnchor.Cq().Text().Trim(); var threadId = url.GetThreadId(); if (0 == threadId) { throw new ProcessFaultException(request, string.Format("无法从第{0}个thread url中获取thread id。", i)); } var header = new ThreadHeader { Id = threadId, Url = url, Title = titleText, ReplyCount = -1 }; var authorText = authorNode.Cq().Text(); if (string.IsNullOrWhiteSpace(authorText)) { return(header); } var values = authorText.Replace("[", "").Replace("]", "").Split('/'); if (values.Length != 4) { return(header); } header.UserName = values[0]; int replyCount; if (int.TryParse(values[1], out replyCount)) { header.ReplyCount = replyCount; } return(header); }
public override bool Matches(IDomObject element) { switch (Mode) { case Modes.Attr: return(Expression.IsMatch(element[Property] ?? "")); case Modes.Css: return(Expression.IsMatch(element.Style[Property] ?? "")); case Modes.Data: return(Expression.IsMatch(element.Cq().DataRaw(Property) ?? "")); default: throw new NotImplementedException(); } }
public static ClassDefinition FromTr(IDomObject domObject) { var tds = domObject.Cq().Children("td").ToList(); var cd = new ClassDefinition { SubjectCode = Amp(tds[0].InnerText), CourseNumber = Amp(tds[1].InnerText), InstructionType = Amp(tds[2].InnerText), InstructionMethod = Amp(tds[3].InnerText), Section = Amp(tds[4].InnerText), CourseTitle = Amp(tds[6].InnerText), Instructor = Amp(tds[8].InnerText) }; var t = domObject.ChildElements.ElementAt(7); var rows = t.FirstElementChild.FirstElementChild.FirstElementChild.ChildElements.ToList(); var days = rows.ElementAt(0); var time = rows.ElementAt(1); cd.Days = ParseDays(days.InnerText); var times = time.InnerText.Split('-'); if (time.InnerText == "TBD") { cd.StartTime = TimeSpan.Zero; cd.EndTime = TimeSpan.Zero; } else { var start = times[0].Trim(); var end = times[1].Trim(); cd.StartTime = DateTime.ParseExact(start, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; cd.EndTime = DateTime.ParseExact(end, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; } var crn = domObject.ChildElements.ElementAt(5).FirstElementChild.FirstElementChild; cd.Crn = crn.InnerText; return(cd); }
private Comment BuildCommentFromHtml(IDomObject fragment) { var cq = fragment.Cq(); var avatar = cq.Select(".avatar"); var comment = new Comment(); comment.Id = fragment["id"].Replace("comment-", ""); comment.Title = cq.Find(">h2").Html(); comment.UserUrl = avatar.Attr("href"); comment.UserImage = avatar.Select("img").Attr("src"); comment.UserName = cq.Find(".user a").Html(); comment.Timestamp = ParseDate(cq.Find(".timestamp a").Html(), hasSeconds: true); comment.Body = cq.Find(".body").Html(); return(comment); }
private ReportItem GetReportItemFromTableRow(IDomObject col1, IDomObject col2) { var textEle = col1.Cq().Select("span.quickedit-content"); var text = textEle.FirstElement().InnerText.Trim(); var url = textEle.Select("span.quickedit-content a").FirstElement().GetAttribute("href"); var dateTime = col2.InnerText; var id = RegExHelper.GetNumberWithRegEx( @"/game\.php\?village=\d+&screen=report&mode=attack&group_id=-1&view=(\d+)", url); var reportItem = new ReportItem { Id = id, Title = text, TimeReceived = dateTime }; return(reportItem); }
private Comment BuildCommentFromHtml(IDomObject fragment) { var cq = fragment.Cq(); var avatar = cq.Select(".avatar"); var comment = new Comment(); comment.Id = fragment["id"].Replace("comment-", ""); comment.Title = cq.Find(">h2").Html(); comment.UserUrl = avatar.Attr("href"); comment.UserImage = avatar.Select("img").Attr("src"); comment.UserName = cq.Find(".user a").Html(); comment.Timestamp = ParseDate(cq.Find(".timestamp a").Html(), hasSeconds: true); comment.Body = cq.Find(".body").Html(); return comment; }
public static ClassDefinition FromDetailTable(IDomObject domObject) { var tds = domObject.Cq().Children("tr").Children("td:last-child").Select(x => x.InnerText.Trim()).ToList(); var d = domObject.Cq() .Parent() .Parent() .Parent() .Siblings() .Find(".tableHeader") .Siblings() .Children() .Select(x => x.InnerText).ToList(); var cd = new ClassDefinition() { Crn = tds[0], SubjectCode = tds[1], CourseNumber = tds[2], Section = tds[3], CourseTitle = tds[5], Campus = tds[6], Instructor = tds[7], InstructionType = tds[8], InstructionMethod = tds[9], MaxEnroll = int.Parse(tds[10]), StartDate = DateTime.Parse(d[0]), EndDate = DateTime.Parse(d[1]), Days = ParseDays(d[3]) }; if (tds[11] == "CLOSED") { cd.Enroll = cd.MaxEnroll; } else { cd.Enroll = int.Parse(tds[11]); } decimal c; if (decimal.TryParse(tds[4], out c)) { cd.MinCredits = cd.MaxCredits = c; } else { var creditsRange = tds[4].Split(new[] { "TO", "OR" }, StringSplitOptions.RemoveEmptyEntries); cd.MinCredits = decimal.Parse(creditsRange[0]); cd.MaxCredits = decimal.Parse(creditsRange[1]); } var times = d[2].Split('-'); if (d[2] == "TBD") { cd.StartTime = TimeSpan.Zero; cd.EndTime = TimeSpan.Zero; } else { var start = times[0].Trim(); var end = times[1].Trim(); cd.StartTime = DateTime.ParseExact(start, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; cd.EndTime = DateTime.ParseExact(end, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; } return(cd); }
private static string ExtractYear(IDomObject dom) { return(dom.Cq().Find(".location_list_header").Elements.First()[4].Cq().Text().Trim()); }