Package org.vietspider.html

Examples of org.vietspider.html.HTMLDocument


public class CharsToken extends Factory<NodeImpl> {
 
  private HTMLDocument document;
 
  public CharsToken() {
    this.document = new HTMLDocument();
  }
View Full Code Here


  public String detectCharset(byte [] bytes) {
    EncodingDetector encodingDetector = new EncodingDetector();
    String codeCharset = encodingDetector.detect(bytes);
    if(codeCharset == null) codeCharset = "utf-8";
    try {
      HTMLDocument document = createDocument(bytes, codeCharset);
      String docCharset = getCharset(document);
      if(docCharset == null
          || charset.equalsIgnoreCase(docCharset)) return codeCharset;
      return docCharset;
    } catch (Exception e) {
View Full Code Here

    NodePathParser pathParser = new NodePathParser();
    HTMLExtractor htmlExtractor = new HTMLExtractor();
   
    byte  [] bytes = download(webClient, "http://news.google.com.vn/");
   
    HTMLDocument document = new HTMLParser2().createDocument(bytes, null);
   
    String [] paths = {
        "BODY[0].TABLE[2].TBODY[0].TR[0].TD[3].TABLE[1].TBODY[0].TR[0].TD[0].TABLE[0].TBODY[0].TR[0].TD[0].DIV[0].TABLE[0].TBODY[0].TR[0].TD[0].DIV[*]"
    };
   
    NodePath [] nodePaths = new NodePath[paths.length];
    for(int i=0; i<paths.length; i++){
      nodePaths[i] = pathParser.toPath(paths[i]);
    }
   
    HTMLDocument doc = htmlExtractor.extract(document, nodePaths);
    System.out.println(doc.getTextValue());
   
    paths = new String[]{
        "DIV[*].BR[*]",
    };
   
    nodePaths = new NodePath[paths.length];
    for(int i=0; i<paths.length; i++){
      nodePaths[i] = pathParser.toPath(paths[i]);
    }
   
    htmlExtractor.remove(doc.getRoot(), nodePaths);
   
    System.out.println(doc.getRoot().getTextValue());
   
    File file = new File("a.html");
    byte[] data = doc.getTextValue().getBytes();
    new DataWriter().save(file, data);
  }
View Full Code Here

    System.out.println("*********************************************************");
  }

  public void viewNode(String path) throws Exception {
    HTMLParser2 parser2 = new HTMLParser2();
    HTMLDocument document  = parser2.createDocument(file, null);
    NodePathParser pathParser = new NodePathParser();
    NodePath nodePath = pathParser.toPath(path);
    HTMLExtractor htmlExtractor = new HTMLExtractor();
    HTMLNode node = htmlExtractor.extract(document, new NodePath[]{nodePath}).getRoot();
    System.out.println(node.getTextValue());
View Full Code Here

    System.out.println(node.getTextValue());
  }

  public HTMLDocument removeNode(String namethrows Exception {
    HTMLParser2 parser2 = new HTMLParser2();
    HTMLDocument document  = parser2.createDocument(file, null);
    removeNode(name, document.getRoot());
    return document;
  }
View Full Code Here

    }
  }

  public List<HTMLNode> getAllNode(String name) throws Exception {
    HTMLParser2 parser2 = new HTMLParser2();
    HTMLDocument document  = parser2.createDocument(file, null);
    List<HTMLNode> list = new ArrayList<HTMLNode>();
    getAllNode(name, document.getRoot(), list);
    return list;
  }
View Full Code Here

    System.out.println("\n"+list.get(15).getTextValue());
    System.out.println("\n"+list.get(15).getParent().getTextValue());
    System.out.println("\n"+list.get(15).getParent().getChildren().size());

    System.out.println("*********************************************************");
    HTMLDocument document = explorer.removeNode("a");
    list = new ArrayList<HTMLNode>();
    explorer.getAllNode("a", document.getRoot(), list);
    System.out.println(list.size());

  }
View Full Code Here

  public static void main(String[] args) {
    try{
      URL url = new URL("http://www.java.net");
//      System.out.println(URLDecoder.decode("video_id=http%3A%2F%2Fliveu-80.vo.llnwd.net%2Fflurl%2Fmb53%2Fnew_media3%2F2006%2F8%2F29%2F174380_media_flash8.flv&homeurl=http%3A%2F%2Fwww.flurl.com%2F&endmovies=http%3A%2F%2Fwww.flurl.com%2Fthumbs.php%3Fid%3D174380&embed=%3Ctable%20border%3D%270%27%20bgcolor%3D%27ffffff%27%20cellpadding%3D%270%27%20cellspacing%3D%270%27%3E%3Ctr%3E%3Ctd%3E%3Cembed%20id%3D%27flurl_media%27%20name%3D%27flurl_media%27%20width%3D%27519%27%20height%3D%27438%27%20src%3D%27http%3A%2F%2Fwww.flurl.com%2Fflvplayer2.swf%3Fvideo%3Dhttp%3A%2F%2Fwww.flurl.com%2Fflash_player_info.php%3Fid%3D174380%26flash%3D8%27%20quality%3D%27high%27%20bgcolor%3D%27white%27%20play%3D%27true%27%20loop%3D%27false%27%20allowScriptAccess%3D%27sameDomain%27%20type%3D%27application%2Fx-shockwave-flash%27%20pluginspage%3D%27http%3A%2F%2Fwww.macromedia.com%2Fgo%2Fgetflashplayer%27%3E%3C%2Fembed%3E%3C%2Ftd%3E%3C%2Ftr%3E%3Ctr%3E%3Ctd%20align%3D%27right%27%3E%3Cstrong%3E%3Ca%20href%3D%27http%3A%2F%2Fwww.flurl.com%2F%27%3EHosted%20on%20Flurl%20Video%20Search%3C%2Fa%3E%20-%20%3Ca%20href%3D%27http%3A%2F%2Fwww.flurl.com%2Fmedia%27%3EWatch%20More%20Videos%3C%2Fa%3E%20%3C%2Fstrong%3E%3C%2Ftd%3E%3C%2Ftr%3E%3C%2Ftable%3E"));
      HTMLParser2 parser2 = new HTMLParser2();
      HTMLDocument document = parser2.createDocument(url.openStream(), "utf-8");

      NodePathParser pathParser = new NodePathParser();
      NodePath nodePath = pathParser.toPath("BODY[0].DIV[0].TABLE[0].TBODY[0].TR[1].TD[3].DIV[10]");
      HTMLExtractor htmlExtractor = new HTMLExtractor();
      HTMLNode node = htmlExtractor.extract(document, new NodePath[]{nodePath}).getRoot();
View Full Code Here

    System.out.println("*********************************************************");   
  }
 
  public List<String> getAttribute(String nodeName, String attrName) throws Exception
    HTMLParser2 parser2 = new HTMLParser2();
    HTMLDocument document  = parser2.createDocument(file, null);
   
    List<String> attrValues = new ArrayList<String>();
   
    NodeIterator iterator = document.getRoot().iterator();
    while(iterator.hasNext()) {
      HTMLNode node = iterator.next();
      if(node.isNode(nodeName)) {
        Attributes attributes = node.getAttributes();
        Attribute attribute = attributes.get(attrName);
View Full Code Here

    return attrValues;
  }
 
  public List<String> getLinks() throws Exception {
    HTMLParser2 parser2 = new HTMLParser2();
    HTMLDocument document  = parser2.createDocument(file, null);
    HyperLinkUtil linkUtil = new HyperLinkUtil() ;
    return linkUtil.scanSiteLink(document.getRoot());
  }
View Full Code Here

TOP

Related Classes of org.vietspider.html.HTMLDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.