1 27 package org.htmlparser.parserapplications; 28 29 import org.htmlparser.beans.StringBean; 30 import org.htmlparser.util.ParserException; 31 32 38 public class StringExtractor 39 { 40 private String resource; 41 42 46 public StringExtractor (String resource) 47 { 48 this.resource = resource; 49 } 50 51 56 public String extractStrings (boolean links) 57 throws 58 ParserException 59 { 60 StringBean sb; 61 62 sb = new StringBean (); 63 sb.setLinks (links); 64 sb.setURL (resource); 65 66 return (sb.getStrings ()); 67 } 68 69 73 public static void main (String [] args) 74 { 75 boolean links; 76 String url; 77 StringExtractor se; 78 79 links = false; 80 url = null; 81 for (int i = 0; i < args.length; i++) 82 if (args[i].equalsIgnoreCase ("-links")) 83 links = true; 84 else 85 url = args[i]; 86 if (null != url) 87 { 88 se = new StringExtractor (url); 89 try 90 { 91 System.out.println (se.extractStrings (links)); 92 } 93 catch (ParserException e) 94 { 95 e.printStackTrace (); 96 } 97 } 98 else 99 System.out.println ("Usage: java -classpath htmlparser.jar org.htmlparser.parserapplications.StringExtractor [-links] url"); 100 } 101 } 102 | Popular Tags |