import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* @author zhaoliangyuan
* @E-mail zhao19860603@163.com
* @dateTime 2010/6/30 上午 11:29:44 类说明:
* java 抓取页面信息
*/
public class Test13 {
public static String getHtmlReadLine(String httpurl){
String CurrentLine="";
String TotalString="";
InputStream urlStream;
String content="";
try {
URL url = new URL(httpurl);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.connect();
urlStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream,"utf-8"));
while ((CurrentLine = reader.readLine()) != null) {
TotalString += CurrentLine+"\n";
/** 换行的地方主要是在这里* */
}
content = TotalString;
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
public static void main(String[] args) {
String s = getHtmlReadLine("http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince");
System.out.println(s);
}
}
java 抓取页面信息
最新推荐文章于 2024-04-27 14:33:28 发布