Example usage for org.jsoup.nodes Document getElementsByAttributeValue

List of usage examples for org.jsoup.nodes Document getElementsByAttributeValue

Introduction

In this page you can find the example usage for org.jsoup.nodes Document getElementsByAttributeValue.

Prototype

public Elements getElementsByAttributeValue(String key, String value) 

Source Link

Document

Find elements that have an attribute with the specific value.

Usage

From source file:com.vina.hlexchang.HttpRequestSample.java

/**
 * @param args the command line arguments
 *///  w  w  w  . j av a2s .  c  o  m
public static void main(String[] args) {
    // TODO code application logic here
    ClientRequestHelper clientRequestHelper = new ClientRequestHelper();
    // clientRequestHelper.setProxy("10.61.11.39", 3128);
    HashMap<String, String> hmR = new HashMap<String, String>();
    hmR.put("User-Agent",
            "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
    hmR.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    hmR.put("Accept-Language", "en-US,en;q=0.5");
    hmR.put("Content-Type", "application/x-www-form-urlencoded");
    String result = clientRequestHelper.sendGet("http://www.otohits.net/account/login", hmR);
    Document doc = Jsoup.parse(result);
    Elements lstElement = doc.getElementsByAttributeValue("name", "__RequestVerificationToken");
    String requestVeriToken = "";
    HashMap<String, String> hmData = new HashMap<>();

    if (lstElement != null && lstElement.size() > 0) {
        requestVeriToken = lstElement.get(0).attr("value");
    }
    hmData.put("__RequestVerificationToken", requestVeriToken);
    hmData.put("Email", "getmoneykhmt3@gmail.com");
    hmData.put("Password", "asd123");
    result = clientRequestHelper.sendPost("http://www.otohits.net/account/login", hmR, hmData);
    System.out.println(result);

}

From source file:httprequestsample.HttpRequestSample.java

/**
 * @param args the command line arguments
 *///w w w  .  j a  va  2 s  . c  o  m
public static void main(String[] args) {
    // TODO code application logic here
    ClientRequestHelper clientRequestHelper = new ClientRequestHelper();
    clientRequestHelper.setProxy("10.61.11.39", 3128);
    HashMap<String, String> hmR = new HashMap<String, String>();
    hmR.put("User-Agent",
            "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
    hmR.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    hmR.put("Accept-Language", "en-US,en;q=0.5");
    hmR.put("Content-Type", "application/x-www-form-urlencoded");
    String result = clientRequestHelper.sendGet("http://www.otohits.net/account/login", hmR);
    Document doc = Jsoup.parse(result);
    Elements lstElement = doc.getElementsByAttributeValue("name", "__RequestVerificationToken");
    String requestVeriToken = "";
    HashMap<String, String> hmData = new HashMap<>();

    if (lstElement != null && lstElement.size() > 0) {
        requestVeriToken = lstElement.get(0).attr("value");
    }
    hmData.put("__RequestVerificationToken", requestVeriToken);
    hmData.put("Email", "getmoneykhmt3@gmail.com");
    hmData.put("Password", "asd123");
    result = clientRequestHelper.sendPost("http://www.otohits.net/account/login", hmR, hmData);
    System.out.println(result);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    final Document document = Jsoup.parse(
            "<html><head/><body><a href=\"#\" class=\"artist\">Soulive<span class=\"create-play\">Play</span></a></body></html>");
    final Element elem = document.getElementsByAttributeValue("class", "artist").first();
    System.out.println(elem.ownText());
}

From source file:com.tianya.ClientMultipartFormPost.java

public static void getCsrfToken(HttpResponse response)
        throws UnsupportedEncodingException, IllegalStateException, IOException {

    if (response != null) {
        Document doc = Jsoup.parse(iotostring(response.getEntity().getContent()));

        csrf_token = doc.getElementsByAttributeValue("name", "csrf_token").get(0).attr("value");

    }//from   w  w  w  . j a v  a  2 s.com

}

From source file:com.gypsai.ClientFormLogin.java

public static void doget() throws ClientProtocolException, IOException {

    String loginUrl = "http://www.cnsfk.com/thread-187338-1-1.html";
    //String loginUrl = "http://renren.com/PLogin.do";

    //String testurl = "http://www.baidu.com";
    HttpGet httpget = new HttpGet(loginUrl);

    httpget.setHeader("User-Agent",
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.28 (KHTML, like Gecko) Chrome/26.0.1397.2 Safari/537.28");

    HttpResponse response = httppostclient.execute(httpget);
    HttpEntity entity = response.getEntity();

    // System.out.println(istostring(entity.getContent()));

    Document doc = Jsoup.parse(istostring(entity.getContent()));

    Elements elements = doc.getElementsByAttributeValue("name", "formhash");

    formhash = elements.get(0).attr("value");

    System.out.println(formhash);

    System.out.println("Login form get: " + response.getStatusLine());

    System.out.println("Request page cookies:");
    List<Cookie> cookies = httppostclient.getCookieStore().getCookies();
    if (cookies.isEmpty()) {
        System.out.println("None");
    } else {/*w w w  .j  a va 2s.co m*/
        for (int i = 0; i < cookies.size(); i++) {
            //     System.out.println("- " + cookies.get(i).toString());
        }
        EntityUtils.consume(entity);

    }

}

From source file:com.daiv.android.twitter.services.TrimDataService.java

public String getVersion() {
    try {/*from ww w .  jav  a 2s . c  o m*/
        Document doc = getDoc();

        if (doc != null) {
            Elements elements = doc.getElementsByAttributeValue("itemprop", "softwareVersion");

            Log.v("Test_version", "elements size: " + elements.size());
            for (Element e : elements) {
                Log.v("Test_version", e.val());
                return e.val();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
    }

    return null;
}

From source file:autoInsurance.BeiJPingAnImpl.java

public String queryBaodhByToubdh(String in) {
    // TODO Auto-generated method stub
    JSONObject jsonObj = JSONObject.fromObject(in);
    String toubdh = jsonObj.getString("toubdh");

    String url = "https://icorepnbs.pingan.com.cn/icore_pnbs/do/app/workbench/qtWaitTaskInfo";
    String postData = "{\"voucherType\":\"1\",\"voucherNo\":\"" + toubdh
            + "\",\"inputById\":\"LGXY-00001\",\"departmentCode\":\"20119\",\"lowDepartment\":true,\"applicantType\":\"\",\"coinsuranceMark\":\"\"}";
    String retStr = httpClientUtil.doPost(url, postData, charset);
    System.out.println(retStr);/* ww w .j  a  va  2  s.  c o  m*/

    url = "https://icorepnbs.pingan.com.cn/icore_pnbs/bussiness/workbench/templates/view/popup/quotationDetail.tpl?voucherNo="
            + toubdh + "&isFromCNBS=false&moduleType=detail&_u=" + HttpClientUtil.digestMap.get(toubdh);
    retStr = httpClientUtil.doGet(url, new HashMap(), charset);
    System.out.println(retStr);

    Document doc = Jsoup.parse(retStr);
    Element elm = doc.getElementsByAttributeValue("language", "javascript").get(0);
    String js = elm.data();
    System.out.println(js);
    String quotationDTO = StringUtils.substringBetween(js, "var quotationDTO = ", " ;");
    System.out.println(quotationDTO);

    Map<String, String> outMap = new HashMap<String, String>();
    //      outMap.put("proposalNo", jObj2.getString("proposalNo"));
    //      outMap.put("policyNo", jObj2.getString("policyNo"));
    //      outMap.put("insuredName", jObj2.getString("insuredName"));
    //      //outMap.put("startDate", jObj2.getString("startDate"));
    //      outMap.put("startDate", timeStamp2Date("" + (Long) ((Map) jObj2.get("startDate")).get("time"), "yyyy-M-d"));

    return JSONObject.fromObject(outMap).toString();
}

From source file:com.klinker.android.twitter.services.TrimDataService.java

public String getVersion() {
    try {//from  ww w  .  j  a v  a 2 s .  c o  m
        Document doc = getDoc();

        if (doc != null) {
            Elements elements = doc.getElementsByAttributeValue("itemprop", "softwareVersion");

            Log.v("talon_version", "elements size: " + elements.size());
            for (Element e : elements) {
                Log.v("talon_version", e.val());
                return e.val();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
    }

    return null;
}

From source file:ac.ucy.cs.spdx.license.License.java

/**
 * License constructor that creates a new License object based on the
 * license url and also the category parameters, which is optional.
 * //from w  w w.j  av  a2  s.  c o m
 * @param String
 * @param Category
 */
public License(String url, Category... category) throws IOException {
    if (category.length != 0)
        this.setCategory(category[0]);
    Document doc = null;

    doc = Jsoup.connect(url).get();

    Element fullName = doc.getElementsByAttributeValue("property", "rdfs:label").get(0);

    this.setLicenseName(fullName.text());

    Element identifier = doc.getElementsByAttributeValue("property", "spdx:licenseId").get(0);
    this.setIdentifier(identifier.text());

    Element licenseText = doc.getElementsByAttributeValue("property", "spdx:licenseText").get(0);
    this.setLicenseText(WordUtils.wrap(licenseText.text(), 80));
    licenses.add(this);
    saveLicense(this);
}

From source file:com.jejking.hh.nord.corpus.AllrisHtmlToRawDrucksache.java

private ImmutableList<String> druckSachenContents(Document htmlDoc) {
    /*/*from w  w w .  j a va  2 s .  co  m*/
     * In this way we can identify the bits of "RTF" like text inserted into the overall HTML.
     * JSoup cleans up the broken HTML removing the xml declaration and inserted html roots
     * that ALLRIS manages to put in.
     */
    Elements contentMetaElements = htmlDoc.getElementsByAttributeValue("name", "generator");
    ImmutableList.Builder<String> listBuilder = ImmutableList.builder();

    /*
     * Iterate over our candidates. Sometimes there are several.
     */
    for (Element contentMetaElement : contentMetaElements) {
        StringBuilder contentAsTextBuilder = new StringBuilder();
        Element nextSibling = contentMetaElement.nextElementSibling();

        /*
         * In the cleaned up HTML DOM returned by JSoup the "RTF" content is
         * rendered as siblings of the meta node (JSoup having removed the html, head, body
         * elements which should never have been there in the first place). 
         */
        while (nextSibling != null && !nextSibling.tag().equals("meta")) {
            contentAsTextBuilder.append(nextSibling.text());
            nextSibling = nextSibling.nextElementSibling();
        }
        /*
         * Only carry over non-empty content.
         */
        String contentAsText = contentAsTextBuilder.toString();
        if (!removeNonBreakingSpacesAndTrim(contentAsText).isEmpty()) {
            listBuilder.add(contentAsText);
        }
    }

    return listBuilder.build();
}