我想做一個請求,並從動態網站得到響應,如果我這樣做與普通瀏覽器(如鉻),並看到源代碼這顯示我所有的文本(沒有javascripts),但如果我嘗試做wget或HttpClient我得到的答覆與JavaScript和沒有文字。HttpClient與javascript
文本是動態的,所以我如何才能接收最終的源代碼(帶有文本)?
請,如果不明確遵循這個步驟:
1 - 進入http://www.stj.jus.br/webstj/processo/Justica/detalhe.asp?numreg=201201911000&pv=010000000000&tp=51
2 - 檢查元件和看到源代碼從detalhe.asp
3 - 打開終端和使用wget爲了得到這個頁面
現在你能看出區別嗎?
---- ----編輯如果 幫助下,我想用HttpClient的做到這一點:
private static InputStream getPageSource(String url) {
InputStream inputStream = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
String responseString = out.toString();
//..more logic
System.out.println(responseString);
inputStream = response.getEntity().getContent();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (Exception e) {
e.printStackTrace();
}
return inputStream;
}
---- EDIT 2 ---- 我做這項工作放在一個字段在標題中:Referer
如果我在執行httpclient之前放了這一行http:get.setHeader(「Referer」,「http://www.stj.jus.br/webstj/processo/Justica/pagina_lista.asp」) ;一切正常..所以,現在的問題是:
如何從HttpClient自動獲取此參數(Referer)?
否 - 如預期的那樣,我得到了兩者的相同答案,但請注意,涉及重定向。也許無論你在做什麼都不遵循重定向? – GreyBeardedGeek
你用什麼命令wget? – kavain
沒有參數的直接wget(在OS X 10.8.2上):「wget http://www.stj.jus.br/webstj/processo/Justica/detalhe.asp?numreg=201201911000&pv=010000000000&tp=51」 – GreyBeardedGeek