18

我想使用 HTTP GET 和 POST 命令从网站检索 URL 并解析 HTML。我该怎么做呢?

4

2 回答 2

21

您可以将HttpURLConnectionURL结合使用。

URL url = new URL("http://example.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();

InputStream stream = connection.getInputStream();
// read the contents using an InputStreamReader
于 2008-12-11T18:02:05.527 回答
3

执行 GET 的最简单方法是使用内置的 java.net.URL。但是,如前所述,httpclient 是正确的方法,因为它可以让您在其他人中处理重定向。

要解析 html,您可以使用html parser

于 2008-12-11T14:25:44.323 回答