1
我正在嘗試登錄到以下網站:http://www.deeproute.com。登錄表單字段是這樣:登錄到網站以抓取java中的數據
<input type="hidden" name="cookieexists" value="false">
<input size=12 type=name name=name>
<input size=12 type=password name=password>
<input type=submit name=subbera value="Login">
這裏是我的代碼中,我試圖用HttpClient的登錄和解析與Jsoup生成的HTML。不幸的是,這會返回相同的未登錄狀態下頁面的原始html。
HttpResponse res = null;
Document homePage = null;
HttpEntity entity = null;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.deeproute.com");
String html = null;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("cookieexists", "false"));
nameValuePairs.add(new BasicNameValuePair("name", username));
nameValuePairs.add(new BasicNameValuePair("password", pass));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
res = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
if (res != null) {
try {
html = EntityUtils.toString(res.getEntity());
homePage = Jsoup.parse(html);
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我該怎麼做才能解決這個問題?