【发布时间】:2012-07-15 15:21:41
【问题描述】:
我正在尝试制作一个需要从网站获取 html 代码并通过代码查找图像的应用程序。我现在所在的位置在模拟器中返回了一个 html 代码,但是当我在计算机上打开网站的源代码时,得到的代码不同。
public String getInternetData(String adresse) throws Exception{
BufferedReader in = null;
String data = null;
try{
HttpClient client = new DefaultHttpClient();
URI website = new URI(adresse);
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) !=null){
sb.append(l + nl);
}
in.close();
data = sb.toString();
return data;
}finally{
if (in != null){
try{
in.close();
return data;
}catch (Exception e){
e.printStackTrace();
}
}
}
}
我在模拟器中获得的代码以需要启用 JavaScript 和 Cookies 结束。如果这是我的问题,我该如何解决?
任何帮助将不胜感激!
【问题讨论】: