tcmrabbit 发表于 2013-2-7 18:51:46

URL读取页面源代码

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;
   }
页: [1]
查看完整版本: URL读取页面源代码