/** * 从页面中提取特定input的的Value * @param formparams * @param document * @param elementId */ private void addFormHiddenElementValue(List<BasicNameValuePair> formparams, Document document, String elementId) { Element element = document.getElementById(elementId); if(element != null){ String elementValue = element.attr("value"); formparams.add(new BasicNameValuePair(elementId,elementValue)); } }
/** * 取得对应URL的Document实例 * @param url * @return */ private static Document getDocument(String url) { Document document = null; try { document = Jsoup.connect(url).get(); } catch (IOException e) { e.printStackTrace(); } return document; }
Document document = getDocument(url); if(document != null){ List<String> elementIds = new ArrayList<String>(); elementIds.add("__VIEWSTATE"); elementIds.add("__VIEWSTATEGENERATOR"); elementIds.add("__EVENTVALIDATION"); for(String elementId : elementIds){ addFormHiddenElementValue(formparams, document, elementId); } }
时间: 2024-10-09 17:53:15