⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlparse.java

📁 一个入门的lucene例子
💻 JAVA
字号:
package com.ou;

/**
 * <p>Title: 搜索引擎</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author 欧阳凯
 * @version 1.0
 */

import java.util.Iterator;
import java.util.Vector;

import com.heaton.bot.HTMLPage;
import com.heaton.bot.HTTP;
import com.heaton.bot.Link;

public class HTMLParse {
  HTTP _http = null;
  public HTMLParse(HTTP http) {
    _http = http;
  }

  /**
   * 对Web页面进行解析后建立索引
   */
  public void start() {
    try {
      HTMLPage _page = new HTMLPage(_http);
      _page.open(_http.getURL(), null);
      Vector _links = _page.getLinks();
      Index _index = new Index();
      Iterator _it = _links.iterator();
      int n = 0;
      while (_it.hasNext()) {
        Link _link = (Link) _it.next();
        System.out.println(_link);
        //有可能会找到xxx.cxx样式表文件和 xxx.ico图片文件,就会报NullPointException
        //如果你运行的时候还出现了其它的不能读取的文件在这里加进来
        String link = _link.toString();
        //获得文件的后坠名
        String name = link.substring(link.lastIndexOf(".")+1);
        if("css".equals(name) || "ico".equals(name)){
        	System.out.println("是样式表文件");
        	continue;
        }
        String _herf = input(_link.getHREF().trim());
        System.out.println(_link.getPrompt().trim());
        String _title = input(_link.getPrompt().trim());
        System.out.println(_title);
        _index.AddNews(_herf, _title);
        n++;
      }
      System.out.println("共扫描到" + n + "条新闻");
      _index.close();
    }
    catch (Exception ex) {
    	ex.printStackTrace();
      System.out.println(ex);
    }
  }
  /**
   * 解决java中的中文问题
   * @param str 输入的中文
   * @return 经过解码的中文
   */
  public static String input(String str) {
    String temp = null;
    if (str != null) {
      try {
        temp = new String(str.getBytes("ISO-8859-1"));
      }
      catch (Exception e) {
      }
    }
    return temp;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -