seeExtracting Links from an HTML File
http://developer.java.sun.com/developer/TechTips/1999/tt0923.html
http://developer.java.sun.com/developer/TechTips/1999/tt0923.html
解决方案 »
- DB2数据插入问题
- javamail邮件客户端开发0之附件上传
- 路径检查了没错,怎么老是出现HTTP Status 404 错误的
- 请问各位大虾,我的servlet在tomcat5.5下为什么还是乱码
- jdk配置的问题
- 刚学servlet,有一个不会写,help me!!!
- 一个大家都遇到的问题,怎么才能计算两个date型的数据,它们相差几个月份,还有几个问题,急!!!!1
- 寻求计算机公司内部网站的解决方案
- 关于文件上传,急急。。。。。。。。。。。
- Spring Security 配置问题 不能拦截url
- Servlet有ServletContext来共享信息,我想在Servlet和JSP之间共享信息,该怎么做?
- 使用javabean增加记录出现的问题,马上结帖!
{
Reader rd = new InputStreamReader(in);
EditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
// The Document class does not yet handle charset's properly.
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
kit.read(rd, doc, 0); // Find all the A elements in the HTML document
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
String link = (String)s.getAttribute(HTML.Attribute.HREF);
if (link != null) {
// Add the link to the result list
//result.add(link);
System.out.println(link);
}
it.next();
}
}
catch (MalformedURLException e)
{
}
catch (BadLocationException e)
{
}
catch (IOException e)
{
}
我用上面的代码输InputStream里面的链接,但是却只显示了/a/b.html,而不是显示"/a/b.html mylink,我需要得到相应的mylink该怎么办呢?
{
System.out.println(
s.getAttribute(HTML.Attribute.HREF) ); System.out.println(doc.getText(elem.getStartOffset(),
elem.getEndOffset() - elem.getStartOffset()));}