基于nat的网吧典型应用
2007-04-30 11:02
337 查看
//获取网页里面的keywords和description public static void main(String[] argv) throws Exception { BufferedReader in = new BufferedReader(new FileReader("d:/163.html")); DOMParser parser = new DOMParser(); parser.setProperty( "http://cyberneko.org/html/properties/default-encoding", "gb2312"); parser.parse(new InputSource(in)); Document doc = parser.getDocument(); NodeList list = doc.getElementsByTagName("META"); for(int i = 0, n = list.getLength(); i < n ; i++){ Element e = (Element) list.item(i); if(e.getAttribute("name").equalsIgnoreCase("keywords")){ String keywords = e.getAttribute("content"); System.out.println("keywords: " + keywords); } if(e.getAttribute("name").equalsIgnoreCase("description")){ String description = e.getAttribute("content"); System.out.println(description); } } } ========================================================================== //2、test使用DOMFragmentParser,提取所有正文,由于没有过滤一些没用的标签,所以会有没用的信息打印,这个可以再事先过滤一下。 public static void main(String[] argv) throws Exception { DOMFragmentParser parser = new DOMFragmentParser(); HTMLDocument document = new HTMLDocumentImpl(); DocumentFragment fragment = document.createDocumentFragment(); parser.parse("http://sports.sina.com.cn/f1/2009-09-21/20104599271.shtml", fragment); print(fragment, ""); } /** Prints a node's class name. */ public static void print(Node node, String indent) { // System.out.println(indent + node.getClass().getName()); // System.out.println(node.getNodeType()); if (node.getNodeType() == Node.TEXT_NODE) { System.out.println(indent + node.getNodeValue()); } Node child = node.getFirstChild(); while (child != null) { print(child, indent + " "); child = child.getNextSibling(); } } }
相关文章推荐
- 三位一体集成技术的典型应用:基于PPT技术的抽奖系统的创作和探索.
- 网吧的典型应用!!!!
- Faas 典型场景——应用负载有显著的波峰波谷,典型用例-基于事件的数据处理
- (AS3)寻找离自己最近的敌人(基于网格,空间换时间的典型应用)
- 基于LVS的NAT模式实现PHP应用
- 基于iptables实现NAT的分析与应用
- LVS基于NAT机制的简单应用配置
- Lvs-nat基于nfs实现php应用
- 4.7/4.8 多项式的表示与处理(数组应用的典型范例2)
- 主流典型各类应用服务器硬件配置分析
- 基于WEB应用开发的java程序员必备工具
- 基于Visual C++ 2010开发Windows7应用-开发多点触控MFC应用程序
- 基于定位的社交应用Foursquare开源网址(wp7)
- DS28E01典型应用及破解方法
- SOA实例:基于SOA的OA与ERP的整合应用
- Android上基于JSON的数据交互应用
- android抓包应用(基于root权限和tcpdump)
- VLAN上配置ACL的典型应用
- 【C++ STL应用与实现】26: 如何使用std::for_each以及基于范围的for循环 (since C++11)