public static SubmitHandler CreateSubmit(PageInfo pi, Question.Choice c) { var sh = new SubmitHandler() { RefPage = pi }; sh.Process(pi.PageContent); sh.KeyValues["answer"] = c.Value; sh.KeyValues[ExpectedRadioName] = pi.Id; sh.KeyValues["page"] = pi.PageId.ToString(); return(sh); }
private Question GetQuestion(string page) { // <strong>问题验证:</strong><font color='#ff0000'>哪个是战斗武器?</font> 选择答案: string pattern = @"<strong>问题验证:</strong>[ ]*<font[^>]+>([^<]*)</font>[ ]*选择答案"; var match = Regex.Match(page, pattern); if (!match.Success) { return(null); } var q = new Question() { Title = match.Groups[1].Value }; // could be like: // <Input name="answer" type="radio" Value="6b49819163"><label style="display:none">49efb</label>8 var start = match.Index + match.Length; for (;;) { var block = page.GetNextNode(start, x => x.ToLower() == "input", true); if (block.OpeningTag.ToLower() == "input") { var t = page.Substring(block.Start, block.ContentStart - block.Start); var val = t.GetAttribute("value"); var inner = page.Substring(block.ContentStart, block.ContentLength); var text = inner.GetTextContent(); var c = new Question.Choice { Value = val, Text = text }; q.Choices.Add(c); } if (block.EndingType == HtmlNodeHelper.NodeInfo.EndingTypes.Mismatched) { // means it reaches the parent node break; } start = block.End; } return(q); }