public String fetchhtml(String _url){
String line,html=new String();
URLConnection urlcon;
BufferedReader br;
try{
URL url = new URL(_url);
urlcon=(HttpURLConnection)url.openConnection();
urlcon.setRequestProperty("User-agent","Mozilla/4.0");
urlcon.connect();
br = new BufferedReader(new InputStreamReader(urlcon.getInputStream(),
Charset.forName("utf-8")));
line = br.readLine();
while(line!=null){
html+=line;
line = br.readLine();
}
}catch(Exception e){
System.out.println("我错了");
}
return html;
}
转载于:https://blog.51cto.com/122178/197031