在Java中查找href链接和URL的内容

Tho*_*dax 6 java href

我想解析这个链接:

<a href="http://www.google.fr">Link to google</a>
Run Code Online (Sandbox Code Playgroud)

为了获得两个结果:

Link = "http://www.google.fr"
LinkName = "Link to google"
Run Code Online (Sandbox Code Playgroud)

我真的不知道怎么做,Java中是否有一个库可以解决这个问题?

提前致谢,

Bit*_*map 0

这样就可以了。

public class Parse
{
  public static void main(String[] args)
  {
    String h = " <a href=\"http://www.google.fr\">Link to google</a>";
    int n = getIndexOf(h, '"', 0);

    String[] a = h.substring(n).split(">");
    String url = a[0].replaceAll("\"", "");
    String value = a[1].replaceAll("</a", "");

    System.out.println(url + " - " + value);
  }

  public static int getIndexOf(String str, char c, int n)
  {
    int pos = str.indexOf(c, 0);
    while (n-- > 0 && pos != -1)
    {
      pos = str.indexOf(c, pos + 1);
    }
    return pos;
  }
}
Run Code Online (Sandbox Code Playgroud)