【发布时间】:2013-10-12 17:36:42
【问题描述】:
我有一个小项目,我正在从网页中抓取信息。作为开始步骤,我开始从
查看页面源代码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 Commons 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?