我希望能够获取一个网页的html并将其保存到一个String
,所以我可以对它进行一些处理.另外,我如何处理各种类型的压缩.
我将如何使用Java进行此操作?
我需要在Java中进行一些非常简单的URL操作.就像在查询中获取参数的值,或者更新它一样,...我期望在commons-lang包中找到一个简单的实用程序类,但是没有.我知道这是一个简单的问题,但是如果已经写了一些东西,为什么还要这样呢?你知道吗?
我想至少具备以下功能:
String myUrl = "http://www.example.com/test.html?toto=1&titi=2";
// get the value of a parameter
String parameterValue = UrlUtils.getParameterValue(myUrl, "toto");
Assert.equals(parameterValue, "1");
// update a parameter
String newUrl = UrlUtils.updateParameter(myUrl, "toto", 3);
parameterValue = UrlUtils.getParameterValue(myUrl, "toto");
Assert.equals(parameterValue, "3");
Run Code Online (Sandbox Code Playgroud)
理想情况下,它会处理所有与编码相关的问题,并使用java.net.Url以及Strings.
谢谢你的帮助 !
我想使用HTTP GET和POST命令从网站检索URL并解析HTML.我该怎么做呢?