我有一個小項目,我正在研究從網頁上抓取信息的地方。作爲一個開始一步,我開始從從網頁中檢索完整頁面的源代碼
http://www.walmart.com/search/search-ng.do?search_query=camera&ic=16_0&Find=Find&search_constraint=0
看頁面的源代碼分析什麼,我需要做的我後試圖檢索使用都是不成功的
首先,我嘗試了兩種方法相同的頁面信息使用Jsoup一個簡單的請求,它看起來像下面
Document doc;
try {
doc = Jsoup.connect("http://www.walmart.com/search/search-ng.do?search_query=camera&ic=16_0&Find=Find&search_constraint=0").get();
System.out.println(doc);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
這帶來了一些網頁信息,但不是實際的頁面源代碼,其中包括所有的搜索結果
然後我試圖和Apache HTTP共享解決方案,它看起來像
String url = "http://www.walmart.com/search/search-ng.do?search_query=camera&ic=16_0&Find=Find&search_constraint=0";
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
HttpResponse response;
try {
response = httpclient.execute(request);
StatusLine status = response.getStatusLine();
String responseString = EntityUtils.toString(response.getEntity());
System.out.println(status);
System.out.println(responseString);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
,但我不斷收到一個頁面永久遷移狀態。
到目前爲止,Jsoup似乎是我前進的最佳選擇。我相信沒有收到所有搜索結果的問題與Jsoup的get函數調用時頁面上的腳本沒有運行有關。
如何獲取所有頁面信息,以便我可以從搜索結果中檢索信息。
您在不回答我的問題的情況下刪除了您的Jsoup問題。你找到了截斷的原因嗎?是你使用的觀衆,而不是Jsoup? –