public void StripTagsRegexCompiled_NoTags() { //Arrange var stringToParse = "Hello World!"; //Act var strippedString = CustomUtlities.StripTagsRegexCompiled(stringToParse); //Assert Assert.AreEqual(stringToParse, strippedString); }
public void StripTagsRegexCompiled_WithTags() { //Arrange var stringToParse = "<html>Hello <strong>World!</strong></html>"; var expectedString = "Hello World!"; //Act var strippedString = CustomUtlities.StripTagsRegexCompiled(stringToParse); //Assert Assert.AreEqual(strippedString, expectedString); }
public IEnumerable <ISearchResult> Parse(string searchHtmlResult) { List <ISearchResult> results = new List <ISearchResult>(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(searchHtmlResult); var searchResultNodes = doc.DocumentNode.SelectNodes(".//li[@class='b_algo']"); //Exit if no results if (searchResultNodes == null) { return(results); } foreach (var node in searchResultNodes) { //TODO: implement exception handling var newResult = new SearchResult(); try { var url = node.SelectSingleNode(".//h2/a").GetAttributeValue("href", ""); var title = node.SelectSingleNode(".//h2/a/@href").InnerHtml; var summary = node.SelectSingleNode(".//div[@class='b_caption']/p").InnerHtml; newResult.Url = CustomUtlities.StripTagsRegexCompiled(url); newResult.Title = CustomUtlities.StripTagsRegexCompiled(title); newResult.Summary = CustomUtlities.StripTagsRegexCompiled(summary); results.Add(newResult); } catch (Exception ex) { newResult.Title = "Error in parsing"; newResult.Summary = ex.Message; } } return(results); }