如何使用java从给定的URL中获取基本URL
||
我正在尝试使用Java获取基本URL。我在代码中使用了jtidy解析器来获取标题。我正在使用jtidy正确获取标题,但没有从给定URL获得基本URL。
我有一些URL作为输入:
String s1 = \"http://staff.unak.is/andy/GameProgramming0910/new_page_2.htm\";
String s2 = \"http://www.complex.com/pop-culture/2011/04/10-hottest-women-in-fast-and-furious-movies\";
从第一个字符串中,我想获取“ 1”作为基本URL,从第二个字符串中,我想要“ 2”作为基本URL。
我正在使用代码:
URL url = new URL(s1);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream in = conn.getInputStream();
Document doc = new Tidy().parseDOM(in, null);
String titleText = doc.getElementsByTagName(\"title\").item(0).getFirstChild()
.getNodeValue();
我得到titletext
,但是请让我知道如何从给定URL上方获取基本URL?
没有找到相关结果
已邀请:
2 个回复
嗓瑰
倪蕊悲潍
对于第二种情况:设置根路径: