private void AddTableHeaders() { var header = new StringBuilder(this.rowStructure); foreach (var column in this.TableColumns) { header = header.Replace("<td>%" + column + "%</td>", "<th>" + column + "</th>"); } table.Append(document.CreateTextNode(header.ToString())); }
public NodeProcessorTests() { _stringParserMock = new Mock <IStringParser>(); _creatorMock = new Mock <INodeCreator>(); _returnedMmsi = 11111111; HtmlNode childNode1 = HtmlNode.CreateNode("<h2> This is h2 heading1</h2>"); HtmlNode childNode2 = HtmlNode.CreateNode("<h2> This is h2 heading2</h2>"); HtmlNode node = new HtmlNode(new HtmlNodeType(), new HtmlDocument(), 0) { InnerHtml = "some_html" }; node.AppendChild(childNode1); node.AppendChild(childNode2); _returnedNodeCollection = new HtmlNodeCollection(new HtmlNode(new HtmlNodeType(), new HtmlDocument(), 0)); _returnedNodeCollection.Append(node); _creatorMock.Setup(mock => mock.CreateNodeCollection(It.IsAny <string>(), It.IsAny <string>())).Returns(_returnedNodeCollection); _creatorMock.Setup(mock => mock.CreatePrepareAndVerifyRowNodeOuterHtml(It.IsAny <string>(), It.IsAny <string>())).Returns("some_node_string"); _stringParserMock.Setup(mock => mock.IsContainingMmsi(It.IsAny <string>())).Returns(true); _stringParserMock.Setup(mock => mock.ParsedInt(It.IsAny <string>())).Returns(_returnedMmsi); _stringParserMock.Setup(mock => mock.GetAisStatusTrimmed(It.IsAny <string>())).Returns("some_status_string"); _stringParserMock.Setup(mock => mock.GetTrimmedTime1(It.IsAny <string>())).Returns("some_date_time_string1"); _stringParserMock.Setup(mock => mock.GetTrimmedTime2(It.IsAny <string>())).Returns("some_date_time_string2"); _stringParserMock.Setup(mock => mock.IsRowTimeRow(It.IsAny <string>())).Returns(true); _stringParserMock.Setup(mock => mock.ParsedTrimmedNullableDateTime(It.IsAny <string>())).Returns(new DateTime(2020, 10, 08)); _service = new NodeProcessor(_stringParserMock.Object, _creatorMock.Object); }
/// <summary> /// 解析URL返回对应标签数据 /// </summary> /// <returns></returns> public Dictionary <int, HtmlNodeCollection> GetGameHtmlInfo() { PubilcHtml pubilcHtml = new PubilcHtml(); var gameHtmlInfos = _gameHtmlInfoServer.GetAll(); Dictionary <int, HtmlNodeCollection> htmlNodes = new Dictionary <int, HtmlNodeCollection>(); HtmlNodeCollection result = new HtmlNodeCollection(null); if (gameHtmlInfos != null) { for (int i = 1; i <= 23; i++) { var html = gameHtmlInfos[0].HtmlUrl.Replace("e378", string.Format("e378?page={0}", i)); var nodeLists = pubilcHtml.ReturnHtmlNode(html, indexTwo); foreach (var node in nodeLists) { result.Append(node); } } var gameList = gameHtmlInfos.Skip(1); foreach (var item in gameList) { var gameHtmlType = item.HtmlUrl.Substring(27); for (int i = 1; i < 400; i++) { GameStrategy gameStrategy = new GameStrategy(); var JsonApi = String.Format("https://www.taptap.com/ajax/search/tags?&kw={0}&sort=hits&page={1}", gameHtmlType, i); var temp = HttpGet(JsonApi, keyValues); JsonHelp jsonHelp = new JsonHelp(); var tempValue = jsonHelp.JsonToObj <GameJson>(temp); var htmlContent = ""; if (tempValue.Data.Html.Contains("img")) { var htmlContentone = tempValue.Data.Html.Replace("<img", "<img style='width:150px;height:150px;margin-top:10px'"); var htmlContentTwo = htmlContentone.Replace("app-card-right app-tag-right", "pull-right col-md-7"); htmlContent = htmlContentTwo.Replace("btn btn-xs btn-default", "btn btn-xs btn-info"); } gameStrategy.content = htmlContent; gameStrategy.GameNodeID = item.GameNodeId.GetValueOrDefault(); gameStrategy.CreateTime = DateTime.Now; Save(gameStrategy); } } htmlNodes.Add(gameHtmlInfos[0].GameNodeId.GetValueOrDefault(), result); } return(htmlNodes); }
private HtmlNodeCollection AppendNodeCollections(HtmlNodeCollection linksInSourcePara, HtmlNodeCollection answersWithLinks) { if (linksInSourcePara == null) { return(answersWithLinks); } else if (answersWithLinks == null) { return(linksInSourcePara); } else { foreach (var node in linksInSourcePara) { answersWithLinks.Append(node); } return(answersWithLinks); } }
private static HtmlDocument GetText(Post p) { var html = new HtmlDocument(); html.LoadHtml(p.Body); // usually these nodes used as a text container var pNodes = html.DocumentNode.SelectNodes("//p | //h1 | //ul | //h2"); var textNodes = new HtmlNodeCollection(html.DocumentNode); foreach (var textNode in pNodes) { // let's ignore image nodes here var imgSpans = textNode.SelectNodes("descendant::span[contains(@class,'confluence-embedded-file-wrapper')]"); if (imgSpans != null && imgSpans.Count > 0) { continue; } textNodes.Append(textNode); } html.DocumentNode.RemoveAllChildren(); foreach (var textNode in textNodes) { html.DocumentNode.AppendChild(textNode); if (html.DocumentNode.InnerHtml.Length > 2000) { break; } } return(html); }