您如何使用Java从html解析链接? [英] How do you parse links from html using Java?

查看:228
本文介绍了您如何使用Java从html解析链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常是Java新手.对于我的班级,我们必须打印出所有要从用户输入的html源代码中解析的链接.

I'm very much a Java novice. For my class we have to print out all of the links that are to be parsed from a user-inputted html source code.

基本上,我想弄清楚如何获取href属性后面的链接字符串,并对网页上的所有链接执行此操作,而无需使用外部方法(即,使用数组,子字符串和字符串方法,但是不会导入其他库).

Basically, I want to figure out how to take the string of the link that comes after the href attribute and do that for all links on the webpage, without using external methods (i.e. using arrays, substrings, and methods of strings but not importing other libraries).

推荐答案

不要使用Parser或RegExp.尝试 Jerry .喜欢(未经测试):

Don't do it with Parser or RegExp. Try Jerry. Like (not tested):

Jerry doc = jerry(html);
doc.$("a").each(new JerryFunction() {
    public boolean onNode(Jerry $this, int index) {
        String href = $this.attr("href");
        System.out.println(href);
    }
}

或任何html友好的查询语言.由于非外部要求,请尝试尝试使用Java解析HTML目录列表中的链接

or any html-friendly query language. Because of non-externals requirements try Trying to parse links in an HTML directory listing using Java

这篇关于您如何使用Java从html解析链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆