SHARE
TWEET

Untitled

a guest Jan 18th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <p class="left_margin"> 5)  
  2. <img src="https://sait.ru/formula/svg/8b/8b847cfae498e96e3fa08a56cb42b838.svg" class="tex" style="vertical-align:0pt" />
  3.     blablabla
  4. </p>
  5.    
  6. var html = @"
  7. <p class='left_margin'> 5)  
  8. <img src='https://sait.ru/formula/svg/8b/8b847cfae498e96e3fa08a56cb42b838.svg' class='tex' style='vertical-align:0pt' />
  9.     blablabla
  10. </p>
  11. ";
  12.  
  13. var doc = new HtmlDocument();
  14. doc.LoadHtml(html);
  15.  
  16. var p = doc.DocumentNode.SelectSingleNode("//p");
  17.  
  18. var textNodes = p.SelectNodes("text()")
  19.     .Select(n => n.InnerText.Trim())
  20.     .ToList();
  21.  
  22. var src = p.SelectSingleNode("img").Attributes["src"].Value;
  23.  
  24. Console.WriteLine(textNodes[0]); // 5)
  25. Console.WriteLine(textNodes[1]); // blablabla
  26. Console.WriteLine(src); // https://sait.ru/formula/svg/8b/8b847cfae498e96e3fa08a56cb42b838.svg
  27.    
  28. var textNodes = p.ChildNodes
  29.     .Where(n => n.NodeType == HtmlNodeType.Text)
  30.     .Select(n => n.InnerText.Trim())
  31.     .ToList();
  32.    
  33. var nodes = p.ChildNodes
  34.     .Select(n => n.NodeType == HtmlNodeType.Text ? n.InnerText.Trim() : n.Attributes["src"].Value);
  35.    
  36. string result = string.Join(" ", nodes);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top