比如下面的代码
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<meta name="robots" content="index,follow" />
<meta name="description" content="Enjoy shopping at online store that offers sporting goods and fitness equipment for the outdoors enthusiasts at discounted prices: product information, apparel, footwear, equipment and accessories for sale." />
<meta name="keywords" content="Shopping, sporting goods, health, fitness, product information, discounted, name brand products, best buy, shoes, fashion, apparel, footwear, equipment, ecommerce, sport, goods, products, sale, store, clothes, accessories" />
有多个META标签,每个META标签的NAME属性的值是我想读的内容。如果我用 if (t==HTML.Tag.META) 那么只能读一个META,怎么样把所有的META标签读入,然后把keyword 和description读到KEYWORD和DESCRIPTION里
protected void attributes(AttributeSet attributes)
  {
    Enumeration e = attributes.getAttributeNames();
    while ( e.hasMoreElements() ) {
      Object name = e.nextElement();
      String value = (String)attributes.getAttribute(name);
下面怎么写,请指教我。我是第一次写JAVA程序好多不懂。
      

解决方案 »

  1.   

    我想做一个简单的搜索引擎。上面的HTML代码是我随便打开一个网页显示的源代码。我想解析HTML代码中的META标签的NAME属性的keyword 和description这2个值的内容。还有TITILE标签包围的内容,然后存到数据库中。数据库表有4列,分别是URL,TITLE,KEYWORD,DESCRIPTION。上面的代码已经通过了编译,但是运行的时候会出现ChangedCharSetException异常。我是第一次写JAVA代码,很多都是抄的,而且自己编程水平非常菜,求各位大侠帮忙改改。自己写的就是class HTMLPageParser extends HTMLEditorKit.ParserCallback 这个类了,想在这个类里面把事情做完。上面还有   try{
       HTMLPageParser callback = new HTMLPageParser(page);
        HTMLPage hpage = new HTMLPage(page);
       hpage.open(hpage.getURL(), callback);}
       catch ( Exception e ) {
          JOptionPane.showMessageDialog(this,
                  e,
                  "Error",
                  JOptionPane.OK_CANCEL_OPTION,
                  null );
        }
    是我添加进去的。我就写了这么多,其他的都是HEATON大哥的。如果需要的话我传给你们。QQ21764290
      

  2.   

    代码在Java J2SE / 基础类问题 同样的贴子中。
      

  3.   

    用正则表达式,参见java.util.regex包