Advertisement
vkorotenko

Untitled

Jun 14th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. static string Cleanup(string d)
  2.         {
  3.             string df = @"
  4. <span>
  5. <style>
  6. .uvkn{display:none}
  7. .LHCZ{display:inline}
  8. .a8eg{display:none}
  9. .QKiO{display:inline}
  10. .rHiv{display:none}
  11. .kNWu{display:inline}
  12. .BnL8{display:none}
  13. .Z6Pm{display:inline}
  14. </style>
  15. <span></span>
  16. <span class=""kNWu"">94</span>
  17. <span class=""79"">.</span>
  18. <span></span>
  19. <span class=""rHiv"">126</span>
  20. <div style=""display:none"">126</div>
  21. <span class=""LHCZ"">198</span>
  22. <span class=""173"">.</span>
  23. <span></span>
  24. <span style=""display: inline"">34</span>
  25. <span style=""display:none"">37</span>
  26. <div style=""display:none"">186</div>
  27. <span class=""213"">.</span>
  28. <div style=""display:none"">23</div>
  29. <span class=""rHiv"">213</span>
  30. <span></span>230</span>";
  31.             HtmlAgilityPack.HtmlNode node =  HtmlNode.CreateNode(df);
  32.             var te = node.SelectSingleNode("//style");
  33.             string t = te.InnerText;
  34.             List<string> hid = new List<string>();
  35.             foreach (var s in t.Split(new string[]{"\r\n"},StringSplitOptions.RemoveEmptyEntries))
  36.             {
  37.                 string name = s.Substring(1,4);
  38.                 string attr = s.Substring(6, s.Length - 7);
  39.                 if(attr.Contains("none"))
  40.                     hid.Add(name);
  41.             }
  42.             var rootNode = te.ParentNode;
  43.             string result = string.Empty;
  44.             foreach (HtmlNode n in rootNode.ChildNodes)
  45.             {
  46.                 if (n.Attributes != null &&
  47.                     n.Attributes.Contains("style") &&
  48.                     n.Attributes["style"].Value.Contains(":none")
  49.                     )
  50.                 {
  51.                     continue;
  52.                 }
  53.                 if (n.Attributes!=null &&
  54.                     n.Attributes.Contains("class")&&
  55.                     hid.Contains(n.Attributes["class"].Value))
  56.                 {
  57.                     continue;
  58.                 }
  59.                 if(n.Name == "style" )
  60.                     continue;
  61.                 result += n.InnerText;
  62.             }
  63.             return result.Replace("\r\n","");
  64.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement