日期:2014-05-18 浏览次数:20745 次
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class PrintPage {
public static void main(String[] args) {
String url_str="http://game.qq.com?ADTAG=media.innerenter.qqcom.indexnavigation";
new PrintPage().show(url_str);
}
public void show(String url_str){
URL url=null;
InputStream is=null;
URLConnection urlc=null;
BufferedReader br=null;
try {
url=new URL(url_str);
urlc=url.openConnection();
urlc.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22");
is=urlc.getInputStream();
br=new BufferedReader(new InputStreamReader(is));
String temp="";
while((temp=br.readLine())!=null)
{
System.out.println(temp);
//Thread.sleep(1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
StringBuffer context = new StringBuffer();try {网页的内容都在context里面了
String line;
URL url = new URL("http://game.qq.com?ADTAG=media.innerenter.qqcom.indexnavigation");
BufferedReader reader = new BufferedReader(new InputStreamReader(
url.openStream(), "utf-8"));
while ((line = reader.readLine()) != null) {
if (!line.equals(""))
context.append(line);
}
reader.close();