public void TestMethod1() { var pUrl = "http://www.sitecore.net/"; var response = HtmlParserHelper.GetWebRequestContent(pUrl); HtmlParserHelper.GetMetaTagsContent(response.Content); HtmlParserHelper.ParseHtml(response.Content); }
public async Task ProcessMessage(Message message) { if (_chatSettingsBotData.ActiveCommand != ActiveCommand.WikiApi) { var inlineKeyboard = new InlineKeyboardMarkup(new[] { new[] { InlineKeyboardButton.WithCallbackData("Travel", "Travel"), InlineKeyboardButton.WithCallbackData("Singing", "Singing"), InlineKeyboardButton.WithCallbackData("Eagle", "Eagle") } }); _chatSettingsBotData.ActiveCommand = ActiveCommand.WikiApi; await _botService.Client.SendTextMessageAsync(message.Chat.Id, "Enter name of article or choose from list: ", replyMarkup : inlineKeyboard); return; } var config = Configuration.Default.WithDefaultLoader().WithCss(); var context = BrowsingContext.New(config); if (string.IsNullOrEmpty(message.Text)) { await _botService.Client.SendTextMessageAsync(message.Chat.Id, "Invalid request"); return; } var source = await context.OpenAsync(BotConstants.Wiki.Url + message.Text); var document = _htmlParser.ParseDocument(source.Body.InnerHtml); var firstParagraph = document.GetElementById("mf-section-0")?.GetElementsByTagName("p"); if (firstParagraph == null) { await _botService.Client.SendTextMessageAsync(message.Chat.Id, "Not found, try again"); return; } var result = HtmlParserHelper.RemoveUnwantedTagsFromHtmlCollection(firstParagraph); var exitKeyboard = KeyboardBuilder.CreateExitButton(); _chatSettingsBotData.ActiveCommand = ActiveCommand.Default; await _botService.Client.SendTextMessageAsync(message.Chat.Id, result, replyMarkup : exitKeyboard); }
public void ConverterTest() { var htmlStr = " <html lang = \"en\"><head>" + " < meta charset = \"utf-8\">" + " < title > MPC - HC WebServer - Variables </title >" + " <link rel = \"stylesheet\" href=\"default.css\">" + " < link rel = \"icon\" href=\"favicon.ico\">" + " < style type = \"text/css\">" + " :root" + " #header + #content > #left > #rlblock_left" + " {display:none !important;}</style ></head >" + " <body class = \"page-variables\">" + " < !--[if lt IE 8]>" + " <div class = \"browser-warning\"><strong>Warning!</strong> You are using an <strong>outdated</strong> browser." + "Please < a href = \"http://browsehappy.com/\">upgrade your browser</a> to improve your experience.</div>" + " < ![endif]-->" + " <p id=\"file\">Gravity.Falls.S01E06.Dipper.vs.Manliness.720p.WEB-DL.AAC2.0.H264-Reaperza.mkv</p>" + " <p id=\"filepatharg\">D:%5cDownloads%5cTorrentDay%5cDownloads%5cGravity.Falls.S01-S02.720p.WEB-DL.AAC2.0.H.264-iT00NZ%5cGravity.Falls.S01.720p.WEB-DL.AAC2.0.H.264-iT00NZ%5cGravity.Falls.S01E06.Dipper.vs.Manliness.720p.WEB-DL.AAC2.0.H264-Reaperza.mkv</p>" + " <p id=\"filepath\">D:\\Downloads\\TorrentDay\\Downloads\\Gravity.Falls.S01-S02.720p.WEB-DL.AAC2.0.H.264-iT00NZ\\Gravity.Falls.S01.720p.WEB-DL.AAC2.0.H.264-iT00NZ\\Gravity.Falls.S01E06.Dipper.vs.Manliness.720p.WEB-DL.AAC2.0.H264-Reaperza.mkv</p>" + " <p id=\"filedirarg\">D:%5cDownloads%5cTorrentDay%5cDownloads%5cGravity.Falls.S01-S02.720p.WEB-DL.AAC2.0.H.264-iT00NZ%5cGravity.Falls.S01.720p.WEB-DL.AAC2.0.H.264-iT00NZ</p>" + " <p id=\"filedir\">D:\\Downloads\\TorrentDay\\Downloads\\Gravity.Falls.S01-S02.720p.WEB-DL.AAC2.0.H.264-iT00NZ\\Gravity.Falls.S01.720p.WEB-DL.AAC2.0.H.264-iT00NZ</p>" + " <p id=\"state\">2</p>" + " <p id=\"statestring\">Playing</p>" + " <p id=\"position\">77149</p>" + " <p id=\"positionstring\">00:01:17</p>" + " <p id=\"duration\">1358858</p>" + " <p id=\"durationstring\">00:22:39</p>" + " <p id=\"volumelevel\">100</p>" + " <p id=\"muted\">1</p>" + " <p id=\"playbackrate\">1</p>" + " <p id=\"size\">532 MB</p>" + " <p id=\"reloadtime\">0</p>" + " <p id=\"version\">1.7.11.0</p>" + " < br ><hr ></body ></html >"; var info = HtmlParserHelper.ParseHtmlToInfo(htmlStr); Assert.Equal("Gravity.Falls.S01E06.Dipper.vs.Manliness.720p.WEB-DL.AAC2.0.H264-Reaperza.mkv", info.FileName); Assert.Equal("D:%5cDownloads%5cTorrentDay%5cDownloads%5cGravity.Falls.S01-S02.720p.WEB-DL.AAC2.0.H.264-iT00NZ%5cGravity.Falls.S01.720p.WEB-DL.AAC2.0.H.264-iT00NZ%5cGravity.Falls.S01E06.Dipper.vs.Manliness.720p.WEB-DL.AAC2.0.H264-Reaperza.mkv", info.FilePathArg); Assert.Equal("D:\\Downloads\\TorrentDay\\Downloads\\Gravity.Falls.S01-S02.720p.WEB-DL.AAC2.0.H.264-iT00NZ\\Gravity.Falls.S01.720p.WEB-DL.AAC2.0.H.264-iT00NZ\\Gravity.Falls.S01E06.Dipper.vs.Manliness.720p.WEB-DL.AAC2.0.H264-Reaperza.mkv", info.FilePath); Assert.Equal("D:%5cDownloads%5cTorrentDay%5cDownloads%5cGravity.Falls.S01-S02.720p.WEB-DL.AAC2.0.H.264-iT00NZ%5cGravity.Falls.S01.720p.WEB-DL.AAC2.0.H.264-iT00NZ", info.FileDirArg); Assert.Equal("D:\\Downloads\\TorrentDay\\Downloads\\Gravity.Falls.S01-S02.720p.WEB-DL.AAC2.0.H.264-iT00NZ\\Gravity.Falls.S01.720p.WEB-DL.AAC2.0.H.264-iT00NZ", info.FileDir); Assert.Equal("Playing", info.StateString); Assert.Equal(State.Playing, info.State); Assert.Equal(77149, info.PositionMillisec); Assert.Equal("532 MB", info.SizeString); Assert.Equal(true, info.Muted); Assert.Equal(100, info.VolumeLevel); }
/// <summary> /// ürün bilgilerini elde edip elastic searche gönderen fonksiyon /// </summary> /// <param name="urlPath">hangi site adresilerinin indexlemede kullanılacağı parametre</param> /// <returns></returns> public static async Task GetUrunlerAndPostElasticSearch(string urlPath) { IHtmlParserHelper _htmlParserManager = new HtmlParserHelper(ConfigurationManager.AppSettings["baseAddress"], urlPath); IElasticSearchService <Urun> _elasticSearchService = new ElasticSearchService <Urun>(ConfigurationManager.AppSettings["aliasName"], ConfigurationManager.AppSettings["indexName"]); var urunler = await _htmlParserManager.GetUrunListesi(); var result = _elasticSearchService.PostToElasticSearch(urunler); if (result.Item1) { Console.WriteLine(string.Format("{0} için Elastic Search indexlemesi başarılı", urlPath)); } else { Console.WriteLine(string.Format("{0} için Elastic Search indexlemesi başarısız. Hata: {1}", urlPath, result.Item2)); } }
private static void ValidateResponse(HttpClientRequest request) { Assert.IsNotNull(request.Response); //parse the response and validate it is correct HttpResponseInfo respInfo = new HttpResponseInfo(); respInfo.ProcessResponse(request.Response); Assert.AreEqual(200, respInfo.Status); //parse the response body XmlDocument dom; HtmlParserHelper.Parse(respInfo, out dom); XmlNode title = dom.SelectSingleNode("//title"); Assert.IsTrue(title.InnerText.Contains("Altoro Mutual: Online Banking Login")); }
private List <HtmlChunk> ParseBml(string bml) { //loop thru bml ////find tag /////if reg'd tag save position found. Take all above bml and move to a string. Find end tag int currentIndex = 0; //int lastChunkStartIndex = 0; int lastChunkEndIndex = 0; List <HtmlChunk> _chunks = new List <HtmlChunk>(); Match lastmatch = null; while (currentIndex < bml.Length) { Match m = null; // Find next opening tags TagRegex bmlTag = new TagRegex(); m = bmlTag.Match(bml, currentIndex); //Check to see if we have a match if (m.Success) { string tagName = HtmlParserHelper.GetTagName(m); if (HtmlParserHelper.IsRegisteredPrefix(tagName)) { lastmatch = m; if (HtmlParserHelper.IsSelfClosingTag(m)) { //Self closing //Add the in between bml as a chunk //Add chunks to list _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, m.Index - lastChunkEndIndex))); //Check to see if its a Region if (HtmlParserHelper.GetTagName(m) == "base:Region") { _chunks.Add(new BmlRegion(m)); } else { _chunks.Add(new HtmlTag(m)); } //SET last chunk index //increment the index by the length of the tag currentIndex = m.Index + m.Length; lastChunkEndIndex = currentIndex; continue; } else { //Not self closing, find end tag string outter = HtmlParserHelper.GetOutterText(bml, m); //add the chunks to the list _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, m.Index - lastChunkEndIndex))); //Check to see if its a Region if (HtmlParserHelper.GetTagName(m) == "base:Region") { _chunks.Add(new BmlRegion(m, outter)); } else { _chunks.Add(new HtmlTag(m, outter)); } //SET last chunk index //increment index the amount of outtertext. currentIndex = m.Index + outter.Length; lastChunkEndIndex = currentIndex; continue; } } } currentIndex++; } //add final chunk _chunks.Add(new HtmlLiteralChunk(bml.Substring(lastChunkEndIndex, bml.Length - lastChunkEndIndex))); return(_chunks); }
public async Task <Info> GetInfo() { var response = await _requestService.ExcuteGetRequest("/variables.html"); return(HtmlParserHelper.ParseHtmlToInfo(response)); }