1 19 20 33 34 package org.htmlparser.parserapplications; 35 import java.util.Enumeration ; 36 import java.util.Vector ; 37 38 import org.htmlparser.Node; 39 import org.htmlparser.Parser; 40 import org.htmlparser.tags.LinkTag; 41 import org.htmlparser.util.DefaultParserFeedback; 42 import org.htmlparser.util.NodeIterator; 43 import org.htmlparser.util.ParserException; 44 45 46 50 public class MailRipper 51 { 52 private org.htmlparser.Parser parser; 53 57 public MailRipper(String resourceLocation) 58 { 59 try 60 { 61 parser = new Parser(resourceLocation, new DefaultParserFeedback()); 62 parser.registerScanners(); 63 } 64 catch (ParserException e) 65 { 66 System.err.println("Could not create parser object"); 67 e.printStackTrace(); 68 } 69 } 70 public static void main(String [] args) 71 { 72 System.out.println("Mail Ripper v" + Parser.getVersion()); 73 if (args.length < 1 || args[0].equals("-help")) 74 { 75 System.out.println(); 76 System.out.println( 77 "Syntax : java -classpath htmlparser.jar org.htmlparser.parserapplications.MailRipper <resourceLocn/website>"); 78 System.out.println(); 79 System.out.println( 80 " <resourceLocn> the name of the file to be parsed (with complete path "); 81 System.out.println( 82 " if not in current directory)"); 83 System.out.println(" -help This screen"); 84 System.out.println(); 85 System.out.println( 86 "HTML Parser home page : http://htmlparser.sourceforge.net"); 87 System.out.println(); 88 System.out.println( 89 "Example : java -classpath htmlparser.jar com.kizna.parserapplications.MailRipper http://htmlparser.sourceforge.net"); 90 System.out.println(); 91 System.out.println( 92 "If you have any doubts, please join the HTMLParser mailing list (user/developer) from the HTML Parser home page instead of mailing any of the contributors directly. You will be surprised with the quality of open source support. "); 93 System.exit(-1); 94 } 95 String resourceLocation = "http://htmlparser.sourceforge.net"; 96 if (args.length != 0) 97 resourceLocation = args[0]; 98 99 MailRipper ripper = new MailRipper(resourceLocation); 100 System.out.println("Ripping Site " + resourceLocation); 101 try 102 { 103 for (Enumeration e = ripper.rip(); e.hasMoreElements();) 104 { 105 LinkTag tag = (LinkTag) e.nextElement(); 106 System.out.println("Ripped mail address : " + tag.getLink()); 107 } 108 } 109 catch (ParserException e) 110 { 111 e.printStackTrace(); 112 } 113 } 114 118 public Enumeration rip() throws ParserException 119 { 120 Node node; 121 Vector mailAddresses = new Vector (); 122 for (NodeIterator e = parser.elements(); e.hasMoreNodes();) 123 { 124 node = e.nextNode(); 125 if (node instanceof LinkTag) 126 { 127 LinkTag linkTag = (LinkTag) node; 128 if (linkTag.isMailLink()) 129 mailAddresses.addElement(linkTag); 130 } 131 } 132 return mailAddresses.elements(); 133 } 134 } 135 | Popular Tags |