【问题标题】:How to parse / split and print the URL? [duplicate]如何解析/拆分和打印 URL? [复制]
【发布时间】:2020-10-18 23:39:12
【问题描述】:

有人可以帮助进行 url 解析拆分吗?

我有如下网址 -

实际 - https://www.facebook.com/group.php/gid=12345
期待 - facebook /group.php/gid=12345

实际 - https://www.Test.this.domain/testPath/
期待 - https wwwtestthisdomain testpath

【问题讨论】:

  • 这能回答你的问题吗? How to split a string in Java
  • 它是如何工作的?第二个有 https 和 www 结果,但第一个只有“facebook”

标签: java url-parsing


【解决方案1】:

您可以使用java.net.URI,如下所示:

    URI uri = URI.create("https://www.facebook.com/group.php/gid=12345");
    System.out.println(
        uri.getPath() // prints: /group.php/gid=12345
    );
    System.out.println(
        uri.getHost() // www.facebook.com
    );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    • 2023-03-10
    • 2020-12-14
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    相关资源
    最近更新 更多