我想使用HTTP GET和POST命令从网站检索URL并解析HTML。我该怎么做呢?
发布于 2008-12-11 18:02:06
您可以将HttpURLConnection与URL结合使用。
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-11 14:25:44
做GET的最简单的方法是使用内置的java.net.URL,但是,正如前面提到的,httpclient是正确的方法,因为它允许你处理重定向。
为了解析html,您可以使用html parser。
https://stackoverflow.com/questions/359439
复制相似问题