1 19 20 package org.htmlparser.tests; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 25 import org.htmlparser.*; 26 import org.htmlparser.scanners.*; 27 import org.htmlparser.tags.*; 28 import org.htmlparser.util.*; 29 30 31 47 48 public class BenchmarkP 49 { 50 51 54 public BenchmarkP() 55 { 56 super(); 57 } 58 59 public static void main(String [] args) 60 { 61 if (args != null && args.length > 0) 62 { 63 String strurl = args[0]; 64 boolean addLink = true; 65 if (args.length == 2) 66 { 67 if (args[1].equals("f")) 68 { 69 addLink = false; 70 } 71 } 72 if (strurl.indexOf("http") < 0) 73 { 74 File input = new File (strurl); 75 try 76 { 77 strurl = input.toURL().toString(); 78 System.out.println("file converted to URL: " + args[0]); 79 } 80 catch (MalformedURLException e) 81 { 82 e.printStackTrace(); 83 } 84 } 85 try 86 { 87 Parser parser = new Parser(strurl, new DefaultParserFeedback()); 88 89 LinkScanner linkScanner = 90 new LinkScanner(LinkTag.LINK_TAG_FILTER); 91 if (addLink) 92 { 93 parser.addScanner(linkScanner); 94 } 95 parser.addScanner( 96 linkScanner.createImageScanner(ImageTag.IMAGE_TAG_FILTER)); 97 parser.addScanner(new BodyScanner()); 98 long start = System.currentTimeMillis(); 99 for (NodeIterator e = parser.elements(); e.hasMoreNodes();) 100 { 101 Node node = e.nextNode(); 102 if (node instanceof BodyTag) 103 { 104 BodyTag btag = (BodyTag) node; 105 System.out.println( 106 "body url: " + btag.getAttribute("background")); 107 for (NodeIterator ee = btag.elements(); 108 ee.hasMoreNodes(); 109 ) 110 { 111 Node cnode = ee.nextNode(); 112 if (cnode instanceof ImageTag) 113 { 114 ImageTag iTag = (ImageTag) cnode; 115 System.out.println( 116 "image url: " + iTag.getImageURL()); 117 } 118 } 119 } 120 } 121 System.out.println( 122 "Elapsed Time ms: " + (System.currentTimeMillis() - start)); 123 } 124 catch (Exception e) 125 { 126 e.printStackTrace(); 127 } 128 } 129 } 130 } 131 | Popular Tags |