public class down {
String text="abc";
String URL="http://zhidao.baidu.com/question/1667030995892031787.html";
HttpClient client=new HttpClient();
GetMethod mythod=new GetMethod(URL);
public void get()
{
try{
int status=client.executeMethod(mythod);
if(status==HttpStatus.SC_OK)
{
text=mythod.getResponseBodyAsString();
System.out.print(text);
}
else{text="cba";}
}catch(Exception e){}
因為我沒找到你的HttpClient和GetMethod兩個類,自己寫了個方法,希望對你有用:
`public static void main(String[] args) throws Exception {
StringBuilder sb = new StringBuilder() ;
String url="http://zhidao.baidu.com/question/1667030995892031787.html";
URL uri = new URL(url);
HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream() , "GBK"));
String line = "" ;
while((line = reader.readLine()) != null){
sb.append(line+"\n");
}
reader.close();
System.out.println(sb.toString());
}
`
當你得到源碼時,希望得到該想要的內容是,一般是要截取相應的字符串,,,,,,