Exemplo n.º 1
0
 public void RemoveNodes(RemoveNode[] nodesToRemove)
 {
     foreach (RemoveNode nodeToRemove in nodesToRemove)
     {
         removeNodes(doc.DocumentNode, nodeToRemove.nodeName, nodeToRemove.attrib, nodeToRemove.attribVal, true);
     }
 }
Exemplo n.º 2
0
        public static void TestRemoveNodeFromUrl()
        {
            String url = "http://www.bbc.co.uk/news/";
            HtmlSanitiser sn = new HtmlSanitiser(url);
            RemoveNode rn1 = new RemoveNode("script", null, null);
            sn.RemoveNodes(new RemoveNode[] { rn1 });

            string htmlout = sn.Html;

            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(htmlout);

            bool foundNode = false;
            if (doc.DocumentNode.Name == "script")
                foundNode = true;
            if(doc.DocumentNode.HasChildNodes)
            {
                foreach(HtmlNode cNode in doc.DocumentNode.ChildNodes)
                    if (cNode.Name == "script")
                    {
                        foundNode = true;
                    }
            }

            if (htmlout.Contains("<script"))
            {
                foundNode = true;
            }

            Assert.AreEqual(foundNode, false);
        }
Exemplo n.º 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string path = txtOutputDir.Text;
            List<RemoveNode> removeNodes = new List<RemoveNode>();
            RemoveNode rn = new RemoveNode("script", null, null);
            removeNodes.Add(rn);
            rn = new RemoveNode("div", "class", "portal");
            removeNodes.Add(rn);
            Downloader dn = new Downloader(path,txtUrl.Text, removeNodes, txtOutputFile.Text + ".html");
            dn.Download();
            string str = "\"" + path + dn.FileName + "\"";
            ProcessStartInfo psi = new ProcessStartInfo(kindleGenExe, str);

            psi.UseShellExecute = false;
            Process p = new Process();
            p.StartInfo = psi;
            p.Start();
            p.WaitForExit();
        }