Esempio n. 1
0
        private (HtmlNode htmlNodeForImagesParsing, HtmlNode htmlNodeForTextParsing) GetHtmlNodesForImageAndText()
        {
            HtmlDocument       loadedFacebookPage = new HtmlWeb().Load(url);
            string             parsingResult      = "";
            string             newLine            = "\n";
            HtmlNodeCollection htmlNodes          = loadedFacebookPage.DocumentNode.SelectNodes("//div[@class = 'hidden_elem']");

            foreach (HtmlNode node in htmlNodes)
            {
                parsingResult += newLine + node.InnerHtml;
            }
            parsingResult = parsingResult.Replace("-->", string.Empty);
            parsingResult = parsingResult.Replace("<!--", string.Empty);
            parsingResult = parsingResult.Replace("<br />", "\n");
            loadedFacebookPage.LoadHtml(parsingResult);
            HtmlNode postMessageNode = loadedFacebookPage.DocumentNode.SelectSingleNode("//div[@data-testid='post_message']");

            return(loadedFacebookPage.DocumentNode, postMessageNode);
        }
Esempio n. 2
0
        static (HtmlNode, HtmlNode) GetHtmlNodesForImageAndText(string id)
        {
            var          url = "https://www.facebook.com/ulanasuprun/posts/" + id;
            HtmlDocument loadedFacebookPage = new HtmlWeb().Load(url);

            string             parsingResult = "";
            string             newLine       = "\n";
            HtmlNodeCollection htmlNodes     = loadedFacebookPage.DocumentNode.SelectNodes("//div[@class = 'hidden_elem']");
            string             a             = loadedFacebookPage.DocumentNode.ChildNodes.ToString();

            foreach (HtmlNode node in htmlNodes)
            {
                parsingResult += newLine + node.InnerHtml;
            }
            parsingResult = parsingResult.Replace("-->", string.Empty);
            parsingResult = parsingResult.Replace("<!--", string.Empty);
            parsingResult = parsingResult.Replace("<br />", "\n");
            loadedFacebookPage.LoadHtml(parsingResult);
            HtmlNode postMessageNode = loadedFacebookPage.DocumentNode.SelectSingleNode("//div[@data-testid='post_message']");

            return(loadedFacebookPage.DocumentNode, postMessageNode);
        }