Java Code Examples for org.jsoup.nodes.Element#val()

The following examples show how to use org.jsoup.nodes.Element#val() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsoupUtil.java    From xxl-crawler with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 抽取元素数据
 *
 * @param fieldElement
 * @param selectType
 * @param selectVal
 * @return String
 */
public static String parseElement(Element fieldElement, XxlCrawlerConf.SelectType selectType, String selectVal) {
    String fieldElementOrigin = null;
    if (XxlCrawlerConf.SelectType.HTML == selectType) {
        fieldElementOrigin = fieldElement.html();
    } else if (XxlCrawlerConf.SelectType.VAL == selectType) {
        fieldElementOrigin = fieldElement.val();
    } else if (XxlCrawlerConf.SelectType.TEXT == selectType) {
        fieldElementOrigin = fieldElement.text();
    } else if (XxlCrawlerConf.SelectType.ATTR == selectType) {
        fieldElementOrigin = fieldElement.attr(selectVal);
    }  else if (XxlCrawlerConf.SelectType.HAS_CLASS == selectType) {
        fieldElementOrigin = String.valueOf(fieldElement.hasClass(selectVal));
    }  else {
        fieldElementOrigin = fieldElement.toString();
    }
    return fieldElementOrigin;
}
 
Example 2
Source File: TestSession.java    From actframework with Apache License 2.0 6 votes vote down vote up
private static boolean matches(Object a, Object b) {
    if ($.eq(a, b)) {
        return true;
    }
    if (!((b instanceof String) && (a instanceof Element))) {
        return false;
    }
    String test = S.string(b);
    Element element = (Element) a;
    // try html
    String html = element.html();
    if (S.eq(html, test, S.IGNORECASE)) {
        return true;
    }
    // try text
    String text = element.text();
    if (S.eq(text, test, S.IGNORECASE)) {
        return true;
    }
    // try val
    String val = element.val();
    if (S.eq(val, test, S.IGNORECASE)) {
        return true;
    }
    return false;
}
 
Example 3
Source File: BaseParser.java    From ZfsoftCampusAssit with Apache License 2.0 5 votes vote down vote up
public String parseViewStateParam(String viewstateHtml) {
    String stateVal = "";
    Document stateHeaderDoc = Jsoup.parse(viewstateHtml);
    Elements elements = stateHeaderDoc.getElementsByTag("input");
    for (Element element : elements) {
        if ("__VIEWSTATE".equals(element.attr("name"))) {
            stateVal = element.val();
            break;
        }
    }
    return stateVal;
}
 
Example 4
Source File: ElectricPresenter.java    From ZfsoftCampusAssit with Apache License 2.0 5 votes vote down vote up
private String parseParamsHeader(Document doc, String key) {
    Elements elements = doc.getElementsByTag("input");
    for (Element element : elements) {
        if (key.equals(element.attr("name"))) {
            return element.val();
        }
    }
    return "";
}
 
Example 5
Source File: Crocko.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
/**
     * Upload a file using the normal upload method (without account).
     */
    private void normalUpload() throws Exception{
        httpPost = new NUHttpPost(postURL);
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        mpEntity.addPart("Filename", new StringBody(file.getName()));
        mpEntity.addPart("Filedata", createMonitoredFileBody());
        httpPost.setEntity(mpEntity);
        NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
        NULogger.getLogger().info("Now uploading your file into crocko");
        uploading();
        httpResponse = httpclient.execute(httpPost, httpContext);
        HttpEntity resEntity = httpResponse.getEntity();

        NULogger.getLogger().info(httpResponse.getStatusLine().toString());
        if (resEntity != null) {
            uploadresponse = EntityUtils.toString(resEntity);
        } else {
            throw new Exception("There might be a problem with your internet connectivity or server error. Please try again later :(");
        }
//  
        gettingLink();
        //NULogger.getLogger().log(Level.INFO, "Upload response : {0}", uploadresponse);
        //FileUtils.saveInFile("Crocko.html", uploadresponse);

        doc = Jsoup.parse(uploadresponse);
        Element element = doc.select("div.msg-ok dl dd input").first();
        if(element != null){
            downloadlink = element.val();
            deletelink = doc.select("div.msg-ok dl dd a.del").first().text();
        }
        else{
            //Handle errors
            status = UploadStatus.GETTINGERRORS;
            String error = doc.select("div.msg-err h4").first().text();
            
            if(error.contains("You exceed upload limit for anonymous user")){
                throw new NUDailyUploadLimitException(dailyUploadAllowance, file.getName(), crockoAccount.getHOSTNAME());
            }
            
            throw new Exception("Error is: "+error);
            // [#136] Use only HttpClient for connections in Crocko.
        }

        if("".equals(downloadlink)){
            status = UploadStatus.GETTINGERRORS;
            throw new Exception("Upload response: "+uploadresponse);
        }

        NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
        NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);

        downURL = downloadlink;
        delURL = deletelink;
        
        uploadFinished();
    }
 
Example 6
Source File: Elements.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set the form element's value in each of the matched elements.
 * @param value The value to set into each matched element
 * @return this (for chaining)
 */
public Elements val(String value) {
    for (Element element : this)
        element.val(value);
    return this;
}
 
Example 7
Source File: Elements.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set the form element's value in each of the matched elements.
 * @param value The value to set into each matched element
 * @return this (for chaining)
 */
public Elements val(String value) {
    for (Element element : this)
        element.val(value);
    return this;
}
 
Example 8
Source File: Elements.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set the form element's value in each of the matched elements.
 * @param value The value to set into each matched element
 * @return this (for chaining)
 */
public Elements val(String value) {
    for (Element element : this)
        element.val(value);
    return this;
}
 
Example 9
Source File: Elements.java    From jsoup-learning with MIT License 4 votes vote down vote up
/**
 * Set the form element's value in each of the matched elements.
 * @param value The value to set into each matched element
 * @return this (for chaining)
 */
public Elements val(String value) {
    for (Element element : contents)
        element.val(value);
    return this;
}
 
Example 10
Source File: ModifySamlResponseStepBuilder.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private HttpUriRequest handlePostBinding(CloseableHttpResponse currentResponse) throws Exception {
    assertThat(currentResponse, statusCodeIsHC(Status.OK));

    final String htmlBody = EntityUtils.toString(currentResponse.getEntity());
    assertThat(htmlBody, Matchers.containsString("SAML"));
    org.jsoup.nodes.Document theResponsePage = Jsoup.parse(htmlBody);
    Elements samlResponses = theResponsePage.select("input[name=SAMLResponse]");
    Elements samlRequests = theResponsePage.select("input[name=SAMLRequest]");
    Elements forms = theResponsePage.select("form");
    Elements relayStates = theResponsePage.select("input[name=RelayState]");
    int size = samlResponses.size() + samlRequests.size();
    assertThat("Checking uniqueness of SAMLResponse/SAMLRequest input field in the page", size, is(1));
    assertThat("Checking uniqueness of forms in the page", forms, hasSize(1));

    Element respElement = samlResponses.isEmpty() ? samlRequests.first() : samlResponses.first();
    Element form = forms.first();

    String base64EncodedSamlDoc = respElement.val();
    InputStream decoded = PostBindingUtil.base64DecodeAsStream(base64EncodedSamlDoc);
    String samlDoc = IOUtils.toString(decoded, GeneralConstants.SAML_CHARSET);
    IOUtils.closeQuietly(decoded);

    String transformed = getTransformer().transform(samlDoc);
    if (transformed == null) {
        return null;
    }

    final String attributeName = this.targetAttribute != null
      ? this.targetAttribute
      : respElement.attr("name");
    List<NameValuePair> parameters = new LinkedList<>();

    if (! relayStates.isEmpty()) {
        parameters.add(new BasicNameValuePair(GeneralConstants.RELAY_STATE, relayStates.first().val()));
    }
    URI locationUri = this.targetUri != null
      ? this.targetUri
      : URI.create(form.attr("action"));

    return createRequest(locationUri, attributeName, transformed, parameters);
}