Example usage for org.jsoup.nodes Element text

List of usage examples for org.jsoup.nodes Element text

Introduction

In this page you can find the example usage for org.jsoup.nodes Element text.

Prototype

public String text() 

Source Link

Document

Gets the combined text of this element and all its children.

Usage

From source file:br.ufsc.das.gtscted.shibbauth.ShibAuthenticationActivity.java

/** Called when the activity is first created. */
@Override/*  w  w w. java 2 s. com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.idp_selection);
    loginButton = (Button) findViewById(R.id.loginButton);
    backButton = (Button) findViewById(R.id.backButton);
    usernameTxt = (EditText) findViewById(R.id.usernameTxt);
    passwordTxt = (EditText) findViewById(R.id.passwordTxt);
    idpSpinner = (Spinner) findViewById(R.id.idpSpinner);

    //Configura o ArrayAdapter do spinner.
    ArrayAdapter<CharSequence> spinnerArrayAdapter;
    spinnerArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    idpSpinner.setAdapter(spinnerArrayAdapter);

    // Obtm os parmetros passados pela Activity anterior 
    // (no caso, a pgina do WAYF como uma String e o
    // nico cookie da Connection usada anteriormente)
    Bundle bundle = this.getIntent().getExtras();
    String wayfHtml = bundle.getString("html_source");
    final String wayfLocation = bundle.getString("wayf_location");
    final SerializableCookie receivedCookie = (SerializableCookie) bundle.getSerializable("cookie");

    //Obtm todos os tags de nome "option", que correspondem
    // aos IdPs, da pgina do WAYF.
    Document wayfDocument = Jsoup.parse(wayfHtml);
    idpElements = wayfDocument.select("option");

    //Popula o spinner com os nomes dos IdPs encontrados.      
    for (Element idpElement : idpElements) {
        String idpName = idpElement.text();
        spinnerArrayAdapter.add(idpName);
    }

    // Obtm o caminho para o qual deve ser passado o IdP do usurio.
    formElements = wayfDocument.select("form");
    for (Element formElement : formElements) {
        if (formElement.attr("id").equals("IdPList")) {
            wayfActionPath = formElement.attr("action");
        }
    }

    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Obtm a URL correspondente ao idP selecionado no spinner.
            int selectedIdpPosition = idpSpinner.getSelectedItemPosition();
            Element selectedIdp = idpElements.get(selectedIdpPosition);
            selectedIdpUrl = selectedIdp.attr("value");

            try {
                // Obtm os campos "username" e "password" fornecidos
                // pelo usurio e necessrios para a autenticao.
                String username = usernameTxt.getText().toString();
                String password = passwordTxt.getText().toString();

                // Cria um novo objeto Connection, e adiciona o 
                // cookie passado pela Activity anterior.
                Connection connection = new Connection();
                BasicClientCookie newCookie = new BasicClientCookie(receivedCookie.getName(),
                        receivedCookie.getValue());
                newCookie.setDomain(receivedCookie.getDomain());
                connection.addCookie(newCookie);

                // Tenta realizar a autenticao no IdP selecionado. O resultado corresponde
                //  pgina para a qual o cliente  redirecionado em caso de autenticao 
                // bem-sucedida.
                String authResult = connection.authenticate(wayfLocation, wayfActionPath, selectedIdpUrl,
                        username, password);

                // Apenas mostra o recurso que o usurio queria acessar (neste caso, mostra a pg. de
                // "Homologao de atributos").
                Intent newIntent = new Intent(ShibAuthenticationActivity.this.getApplicationContext(),
                        TestActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("arg", authResult);
                newIntent.putExtras(bundle);
                startActivity(newIntent);

            } catch (IOException e) {
                String message = "IOException - problema na conexo";
                Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
                toast.show();
            } catch (Exception e) {
                String message = "Exception - problema na autenticao";
                Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
                toast.show();
            }
        }
    });

    backButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

}

From source file:de.geeksfactory.opacclient.apis.BiBer1992.java

static List<LentItem> parseMediaList(AccountData res, Document doc, JSONObject data) throws JSONException {
    List<LentItem> media = new ArrayList<>();
    if (doc == null) {
        return media;
    }/* w  w w  .j av  a 2 s. com*/

    // parse result list
    JSONObject copymap = data.getJSONObject("accounttable");

    Pattern expire = Pattern.compile("Ausweisg.ltigkeit: ([0-9.]+)");
    Pattern fees = Pattern.compile("([0-9,.]+) .");
    for (Element td : doc.select(".td01x09n")) {
        String text = td.text().trim();
        if (expire.matcher(text).matches()) {
            res.setValidUntil(expire.matcher(text).replaceAll("$1"));
        } else if (fees.matcher(text).matches()) {
            res.setPendingFees(text);
        }
    }
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
    Elements rowElements = doc.select("form[name=medkl] table tr");

    // rows: skip 1st row -> title row
    for (int i = 1; i < rowElements.size(); i++) {
        Element tr = rowElements.get(i);
        if (tr.child(0).tagName().equals("th")) {
            continue;
        }
        LentItem item = new LentItem();

        Pattern itemIdPat = Pattern.compile("javascript:smAcc\\('[a-z]+','[a-z]+','([A-Za-z0-9]+)'\\)");
        // columns: all elements of one media
        Iterator<?> keys = copymap.keys();
        while (keys.hasNext()) {
            String key = (String) keys.next();
            int index;
            try {
                index = copymap.has(key) ? copymap.getInt(key) : -1;
            } catch (JSONException e1) {
                index = -1;
            }
            if (index >= 0) {
                String value = tr.child(index).text().trim().replace("\u00A0", "");

                switch (key) {
                case "author":
                    value = findTitleAndAuthor(value)[1];
                    break;
                case "title":
                    value = findTitleAndAuthor(value)[0];
                    break;
                case "returndate":
                    try {
                        value = fmt.parseLocalDate(value).toString();
                    } catch (IllegalArgumentException e1) {
                        e1.printStackTrace();
                    }
                    break;
                }

                if (tr.child(index).select("a").size() == 1) {
                    Matcher matcher = itemIdPat.matcher(tr.child(index).select("a").attr("href"));
                    if (matcher.find())
                        item.setId(matcher.group(1));
                }

                if (value != null && value.length() != 0)
                    item.set(key, value);
            }
        }

        if (tr.select("input[type=checkbox][value=YES]").size() > 0) {
            item.setProlongData(tr.select("input[type=checkbox][value=YES]").attr("name"));
        }

        media.add(item);
    }
    return media;
}

From source file:org.sbs.goodcrawler.extractor.selector.PageElementSelector.java

@SuppressWarnings("unchecked")
@Override//w  w  w  . j  a  v a2  s .com
public HashMap<String, Object> getContent() throws ExtractException {
    if (null != content && !newDoc) {
        return content;
    }
    // ??document
    if (!newDoc) {
        return content;
    }
    // ?documentSelector
    List<String> urls = Lists.newArrayList();
    if (super.document != null) {
        Elements elements = super.document.select(value);
        if (elements.isEmpty())
            return null;
        switch ($Attr) {
        case text:
            for (Element e : elements) {
                urls.add(e.text());
            }
            break;
        default:
            for (Element e : elements) {
                urls.add(e.attr(attr));
            }
            break;
        }
    }
    if (urls.size() > 0) {
        content = Maps.newHashMap();
        for (String url : urls) {
            Document doc = null;
            PageFetchResult result = null;
            try {
                WebURL webUrl = new WebURL();
                webUrl.setURL(url);
                result = FetchForeman.fetcher.fetchHeader(webUrl);
                // ??
                int statusCode = result.getStatusCode();
                if (statusCode == CustomFetchStatus.PageTooBig) {
                    return null;
                }
                if (statusCode != HttpStatus.SC_OK) {
                    return null;
                } else {
                    Page page = new Page(webUrl);
                    if (!result.fetchContent(page)) {
                        return null;
                    }
                    if (!parser.parse(page, webUrl.getURL())) {
                        return null;
                    }
                    doc = Jsoup.parse(new String(page.getContentData(), page.getContentCharset()),
                            urlUtils.getBaseUrl(page.getWebURL().getURL()));
                }
            } catch (IOException e) {
                e.printStackTrace();
                throw new ExtractException(e.getMessage());
            } finally {
                if (result != null)
                    result.discardContentIfNotConsumed();
            }

            if (selectors != null)
                for (AbstractElementCssSelector<?> selector : selectors) {
                    if (selector instanceof FileElementCssSelector) {
                        Map<String, Object> m = ((FileElementCssSelector) selector).setResult(content)
                                .setDocument(doc).getContentMap();
                        if ((null == m || m.size() == 0) && selector.isRequired()) {
                            return null;
                        } else {
                            if (null != m && m.size() > 0)
                                content = MapUtils.mager(content, (HashMap<String, Object>) m);
                        }
                    } else {
                        Map<String, Object> m = selector.setDocument(doc).getContentMap();
                        if ((null == m || m.size() == 0) && selector.isRequired()) {
                            return null;
                        } else {
                            if (null != m && m.size() > 0)
                                content = MapUtils.mager(content, (HashMap<String, Object>) m);
                        }
                    }
                }
        }
        return content;
    }
    newDoc = false;
    return null;
}

From source file:org.brunocvcunha.taskerbox.impl.crawler.PastebinAction.java

@Override
public void action(final Document entry) {

    log.debug("Validating " + entry.title());

    for (Element el : entry.select(".maintable").select("a")) {
        final String id = el.attr("href").substring(1);
        if (id.startsWith("archive")) {
            continue;
        }//from   w w w  . ja v  a 2 s  . c  o m

        final String title = id + " - " + el.text();

        if (canAct(id)) {
            addAct(id);

            spreadAction(id, title);
            serializeAlreadyAct();
            sleep(FETCH_INTERVAL);
        }

    }

}

From source file:net.pixomania.crawler.W3C.parser.rules.editors.EditorsRule2.java

@Override
public ArrayList<Person> run(String url, Document doc) {
    ArrayList<Person> editorList = new ArrayList<>();

    Elements editors = doc.select("dt:contains(Editor) ~ dd, dt:contains(Edition Editor) ~ dd");
    if (editors.size() == 0)
        return null;

    boolean skip = false;
    for (Element editor : editors) {
        Element prev = editor.previousElementSibling();
        if (prev.tagName().equals("dt")) {
            if ((!prev.text().trim().toLowerCase().startsWith("editor")
                    && !prev.text().trim().toLowerCase().startsWith("edition editor"))
                    || prev.text().trim().toLowerCase().contains("version")
                    || prev.text().trim().toLowerCase().endsWith("draft:")) {
                skip = true;//from  w w w .j  a  v a2 s .c  om
            }
        }

        if (skip) {
            Element next = editor.nextElementSibling();
            if (next != null) {
                if (next.text().trim().toLowerCase().startsWith("editor")
                        || next.text().trim().toLowerCase().contains("edition editor")) {
                    skip = false;
                    continue;
                }
            }
            continue;
        }

        if (StringUtils.countMatches(editor.text(), " - ") > 2) {
            Log.log("warning", "This editor may be a list of editors separated by  - ");
            EditorsRule5 ed5 = new EditorsRule5();

            return ed5.run(url, doc);
        }

        String[] splitted = editor.html().split("<br />|<br clear=\"none\" />");

        if (splitted.length < 2) {
            if (editor.text().toLowerCase().startsWith("(in alphabetic")
                    || editor.text().toLowerCase().startsWith("see acknowl")
                    || editor.text().toLowerCase().startsWith("the w3")
                    || editor.text().toLowerCase().startsWith("(see ac")
                    || editor.text().toLowerCase().startsWith("see participants")
                    || editor.text().toLowerCase().contains("note:")) {
                Log.log("warning", "Spec " + url + " may refer to a different section!");
                continue;
            }
            if (editor.text().equals("WHATWG:") || editor.text().equals("W3C:"))
                continue;
            Person result = NameParser.parse(editor.text());
            if (result == null)
                continue;

            for (int i = 0; i < editor.select("a").size(); i++) {
                if (!editor.select("a").get(i).attr("href").isEmpty()) {
                    if (editor.select("a").get(i).attr("href").contains("@")) {
                        result.setEmail(editor.select("a").get(i).attr("href").replace("mailto:", ""));
                    } else {
                        result.addWebsite(editor.select("a").get(i).attr("href"));
                    }
                }
            }

            editorList.add(result);
        } else {
            for (String split : splitted) {
                if (!split.isEmpty()) {
                    if (split.toLowerCase().startsWith("(in alphabetic")
                            || split.toLowerCase().startsWith("see acknowl")
                            || split.toLowerCase().startsWith("the w3")
                            || split.toLowerCase().startsWith("(see ac")
                            || split.toLowerCase().startsWith("see participants")
                            || split.toLowerCase().contains("note:")) {
                        Log.log("warning", "Spec " + url + " may refer to a different section!");
                        continue;
                    }
                    if (split.equals("WHATWG:") || split.equals("W3C:"))
                        continue;
                    Document newdoc = Jsoup.parse(split.replaceAll("\n", ""));
                    Person result = NameParser.parse(newdoc.text());
                    if (result == null)
                        continue;

                    for (int i = 0; i < newdoc.select("a").size(); i++) {
                        if (!newdoc.select("a").get(i).attr("href").isEmpty()) {
                            if (newdoc.select("a").get(i).attr("href").contains("@")) {
                                result.setEmail(newdoc.select("a").get(i).attr("href").replace("mailto:", ""));
                            } else {
                                result.addWebsite(newdoc.select("a").get(i).attr("href"));
                            }
                        }
                    }

                    editorList.add(result);
                }
            }
        }

        Element next = editor.nextElementSibling();
        if (next != null)
            if (next.tag().getName().equals("dt"))
                break;
    }

    if (editorList.size() == 0)
        return null;

    return editorList;
}

From source file:net.pixomania.crawler.W3C.parser.rules.editors.EditorsRule8.java

@Override
public ArrayList<Person> run(String url, Document doc) {
    ArrayList<Person> editorList = new ArrayList<>();

    Elements editors = doc.select("h4:contains(Editor) ~ blockquote");
    if (editors.size() == 0)
        return null;

    boolean skip = false;
    for (Element editor : editors) {
        Element prev = editor.previousElementSibling();
        if (prev.tagName().equals("h4")) {
            if ((!prev.text().trim().toLowerCase().startsWith("editor")
                    && !prev.text().trim().toLowerCase().startsWith("edition editor"))
                    || prev.text().trim().toLowerCase().endsWith("version:")
                    || prev.text().trim().toLowerCase().endsWith("draft:")) {
                skip = true;//w w w.  j av  a  2  s.  co  m
            }
        }

        if (skip) {
            Element next = editor.nextElementSibling();
            if (next != null) {
                if (next.text().trim().toLowerCase().startsWith("editor")
                        || next.text().trim().toLowerCase().contains("edition editor")) {
                    skip = false;
                    continue;
                }
            }
            continue;
        }

        if (StringUtils.countMatches(editor.text(), " - ") > 2) {
            Log.log("warning", "This editor may be a list of editors separated by  - ");
            EditorsRule5 ed5 = new EditorsRule5();

            return ed5.run(url, doc);
        }

        String[] splitted = editor.html().split("<br />|<br clear=\"none\" />");

        if (splitted.length < 2) {
            if (editor.text().toLowerCase().startsWith("(in alphabetic")
                    || editor.text().toLowerCase().startsWith("see acknowl")
                    || editor.text().toLowerCase().startsWith("the w3")
                    || editor.text().toLowerCase().startsWith("(see ac")
                    || editor.text().toLowerCase().startsWith("see participants")
                    || editor.text().toLowerCase().contains("note:")) {
                Log.log("warning", "Spec " + url + " may refer to a different section!");
                continue;
            }
            if (editor.text().equals("WHATWG:") || editor.text().equals("W3C:"))
                continue;
            Person result = NameParser.parse(editor.text());
            if (result == null)
                continue;

            for (int i = 0; i < editor.select("a").size(); i++) {
                if (!editor.select("a").get(i).attr("href").isEmpty()) {
                    if (editor.select("a").get(i).attr("href").contains("@")) {
                        result.setEmail(editor.select("a").get(i).attr("href").replace("mailto:", ""));
                    } else {
                        result.addWebsite(editor.select("a").get(i).attr("href"));
                    }
                }
            }

            editorList.add(result);
        } else {
            for (String split : splitted) {
                if (!split.isEmpty()) {
                    if (split.toLowerCase().startsWith("(in alphabetic")
                            || split.toLowerCase().startsWith("see acknowl")
                            || split.toLowerCase().startsWith("the w3")
                            || split.toLowerCase().startsWith("(see ac")
                            || split.toLowerCase().startsWith("see participants")
                            || split.toLowerCase().contains("note:")) {
                        Log.log("warning", "Spec " + url + " may refer to a different section!");
                        continue;
                    }
                    if (split.equals("WHATWG:") || split.equals("W3C:"))
                        continue;
                    Document newdoc = Jsoup.parse(split.replaceAll("\n", ""));
                    Person result = NameParser.parse(newdoc.text());
                    if (result == null)
                        continue;

                    for (int i = 0; i < newdoc.select("a").size(); i++) {
                        if (!newdoc.select("a").get(i).attr("href").isEmpty()) {
                            if (newdoc.select("a").get(i).attr("href").contains("@")) {
                                result.setEmail(newdoc.select("a").get(i).attr("href").replace("mailto:", ""));
                            } else {
                                result.addWebsite(newdoc.select("a").get(i).attr("href"));
                            }
                        }
                    }

                    editorList.add(result);
                }
            }
        }

        Element next = editor.nextElementSibling();
        if (next != null)
            if (next.tag().getName().equals("h4"))
                break;
    }

    if (editorList.size() == 0)
        return null;

    return editorList;
}

From source file:lolthx.autohome.buy.AutohomePriceListFetch.java

@Override
public void parse(String result, Task task) throws Exception {
    if (StringUtils.isBlank(result)) {
        return;//from   w w  w .j a  v  a  2  s  .co m
    }

    Date start = task.getStartDate();
    Date end = task.getEndDate();

    Document doc = Jsoup.parse(result);
    Elements lis = doc.select("li.price-item");

    AutohomePriceInfoBean bean = new AutohomePriceInfoBean();

    for (Element li : lis) {

        try {
            Elements postTimeEl = li.select("div.user-name span");
            String postTime = "";
            if (!postTimeEl.isEmpty()) {
                postTime = StringUtils.trim(
                        StringUtils.substringBefore(postTimeEl.first().text(), "?").replaceAll("", ""));

                if (!isTime(postTime, start, end)) {
                    continue;
                }
            }
            bean.setPostTime(postTime);
            bean.setUrl(task.getUrl());
            bean.setForumId(StringUtils.substringBefore(task.getExtra(), ":"));
            bean.setProjectName(task.getProjectName());
            bean.setKeyword(StringUtils.substringAfter(task.getExtra(), ":"));

            // post id
            Elements id = li.select("div.price-share a.share");
            if (!id.isEmpty()) {
                String idStr = id.first().attr("data-target");
                idStr = StringUtils.substringAfterLast(idStr, "_");
                if (StringUtils.isBlank(idStr)) {
                    continue;
                }

                bean.setId(idStr);
            }

            // 
            Elements user = li.select("div.user-name a");
            if (!user.isEmpty()) {
                String userUrl = user.first().absUrl("href");
                String userId = StringUtils.substringAfterLast(userUrl, "/");
                String userName = user.first().text();

                bean.setUserId(userId);
                bean.setUserUrl(userUrl);
                bean.setUserName(userName);
            }

            Elements dataLis = li.select("div.price-item-bd li");
            for (Element dataLi : dataLis) {
                String data = dataLi.text();

                if (StringUtils.startsWith(data, "")) {
                    bean.setCar(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setPrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setGuidePrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "?")) {
                    bean.setTotalPrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setPurchaseTax(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "?")) {
                    bean.setCommercialInsurance(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setVehicleUseTax(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setCompulsoryInsurance(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setLicenseFee(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "?")) {
                    bean.setPromotion(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setBuyTime(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    String area = StringUtils.trim(StringUtils.substringAfter(data, ""));
                    String[] pAndC = StringUtils.splitByWholeSeparator(area, ",", 2);

                    if (pAndC.length == 1) {
                        bean.setBuyProvince(pAndC[0]);
                        bean.setBuyCity(pAndC[0]);
                    }

                    if (pAndC.length == 2) {
                        bean.setBuyProvince(pAndC[0]);
                        bean.setBuyCity(pAndC[1]);
                    }

                }
                if (StringUtils.startsWith(data, "")) {
                    Elements level = dataLi.select("span.level");
                    // 
                    if (!level.isEmpty()) {
                        bean.setSellerComment(level.first().text());
                    }

                    // ?
                    Elements seller = dataLi.select("a.title");
                    if (!seller.isEmpty()) {
                        String sellerUrl = seller.first().absUrl("href");
                        String sellerName = seller.first().text();
                        String sellerId = StringUtils.substringAfterLast(sellerUrl, "/");

                        bean.setSellerId(sellerId);
                        bean.setSellerName(sellerName);
                        bean.setSellerUrl(sellerUrl);
                    }

                    // ?
                    Elements sellerPhone = dataLi.select("em.phone-num");
                    if (!sellerPhone.isEmpty()) {
                        bean.setSellerPhone(sellerPhone.first().text());
                    }

                    // ?
                    // Elements sellerAddress =
                    // dataLi.select("em.phone-num");

                }
                if (StringUtils.startsWith(data, "?")) {
                    bean.setBuyFeeling(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
            }
            bean.saveOnNotExist();
        } catch (Exception e) {
            e.printStackTrace();
            continue;
        }
    }
}

From source file:am.roadpolice.roadpolice.downloaders.Submitter.java

/**
 * This function process URL and collect needed information about
 * violation and add it to Violation List (mViolationInfoList).
 *
 * @param url URL from which data will be processed.
 * @return null if no error occurs; otherwise ERROR1/ERROR2 if something
 * was changed in server behaviour,  ERROR3 if error occurs while trying
 * to get JSOUP document, or server error text.
 *//*from ww w .  j ava 2 s .  c om*/
private String processUrl(final String url) {
    Logger.debugLine();
    Logger.debug(TAG, "Processing URL: " + url);

    HttpGet httpGet = new HttpGet(url);
    HttpParams httpParameters = new BasicHttpParams();
    // Set the timeout in milliseconds until a connection is established.
    // The default value is zero, that means the timeout is not used.
    HttpConnectionParams.setConnectionTimeout(httpParameters, CONNECT_TIMEOUT);
    // Set the default socket timeout (SO_TIMEOUT)
    // in milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setSoTimeout(httpParameters, SOCKET_TIMEOUT);
    DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);

    try {

        HttpResponse response = httpClient.execute(httpGet);
        java.util.Scanner s = new java.util.Scanner(response.getEntity().getContent()).useDelimiter("\\A");

        Document document = Jsoup.parse(s.hasNext() ? s.next() : null);
        // In the case if  some data  was provided not correct in
        // the url server generates page with red text, we handle
        // this situation and return text in the red block.
        Elements errorElement = document.getElementsByClass("red");
        if (errorElement != null && errorElement.first() != null) {
            final String errorText = errorElement.first().text();
            Logger.debug(TAG, "Found Error Element (RED): " + errorText);
            return errorText;
        }

        Elements tableElements = document.getElementsByClass("dahk_yes");
        tableElements.addAll(document.getElementsByClass("dahk_no"));
        for (Element element : tableElements) {
            Elements tdElements = element.getElementsByTag("td");

            int tdElementsCount = ViolationInfo.COL_OWNER_FULL_NAME;
            ViolationInfo violationInfo = null;
            for (Element tdElement : tdElements) {
                final String text = tdElement.text().trim();

                // We found vehicle registration number.
                if (text.equalsIgnoreCase(mRegNum)) {
                    // Create new class object to store data.
                    violationInfo = new ViolationInfo(mRegNum);
                    violationInfo.setCertificateNumber(mCerNum);
                    continue;
                }

                // Violation Info object was not created, reason can be
                // that something is changed on the server side.
                if (violationInfo == null) {
                    return ERROR_ON_SERVER_SIDE;
                }

                switch (tdElementsCount) {
                case ViolationInfo.COL_OWNER_FULL_NAME:
                    violationInfo.setOwnerFullName(text);
                    break;

                case ViolationInfo.COL_OWNER_ADDRESS:
                    violationInfo.setOwnerAddress(text);
                    break;

                case ViolationInfo.COL_TO_PAY:
                    violationInfo.setToPay(text);
                    break;

                case ViolationInfo.COL_PAYED:
                    violationInfo.setPayed(text);
                    break;

                case ViolationInfo.COL_CAR_MODEL:
                    violationInfo.setCarModel(text);
                    break;

                case ViolationInfo.COL_THE_DECISION:
                    // Do Nothing ...
                    break;

                case ViolationInfo.COL_DATE:
                    violationInfo.setDate(text);
                    break;

                case ViolationInfo.COL_PIN:
                    violationInfo.setPin(text);
                    break;

                default:
                    return ERROR_WHILE_PARSING_DATA;
                }

                tdElementsCount++;
            }

            // Add items to the list.
            mViolationInfoList.add(violationInfo);
        }
    } catch (IOException e) {
        Logger.error(TAG, "----> Exception occurs while trying to get JSOUP document.");
        Logger.error(TAG, "----> Message: " + e.getMessage());
        return ERROR_WHILE_CREATING_JSOUP;
    }

    return null;
}

From source file:com.liato.bankdroid.banking.banks.Jojo.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }/*from   ww w  .  j  ava  2  s  . com*/
    urlopen = login();
    Document d = Jsoup.parse(response);

    Elements es = d.select(".saldo_ok_wrapper > table > tbody tr");
    if (es != null) {
        for (int i = 0; i < 2; i++) {

            int index = 0 + i;
            if (es.size() >= index) {
                Element e = es.get(index);
                Element name = e.select(".first").first();
                Element amount = e.select(".right").first();
                if (name != null && amount != null) {
                    Account a = new Account(name.text().replaceAll(":", "").trim(),
                            Helpers.parseBalance(amount.text()), Integer.toString(i));
                    accounts.add(a);
                    balance = balance.add(a.getBalance());
                }
            }
        }
    }

    if (accounts.isEmpty()) {
        throw new BankException(res.getText(R.string.no_accounts_found).toString());
    }
    super.updateComplete();
}

From source file:com.johan.vertretungsplan.parser.UntisInfoParser.java

@Override
public Vertretungsplan getVertretungsplan() throws IOException, JSONException {
    new LoginHandler(schule).handleLogin(executor, cookieStore, username, password);

    Document navbarDoc = Jsoup.parse(getNavbarDoc().replace("&nbsp;", ""));
    Element select = navbarDoc.select("select[name=week]").first();

    Vertretungsplan v = new Vertretungsplan();
    List<VertretungsplanTag> tage = new ArrayList<VertretungsplanTag>();

    String info = navbarDoc.select(".description").text();
    String stand;//from  w  ww  .  j a va 2 s.c om
    try {
        stand = info.substring(info.indexOf("Stand:"));
    } catch (Exception e) {
        stand = "";
    }

    for (Element option : select.children()) {
        String week = option.attr("value");
        String letter = data.optString("letter", "w");
        if (data.optBoolean("single_classes", false)) {
            int classNumber = 1;
            for (String klasse : getAllClasses()) {
                String paddedNumber = String.format("%05d", classNumber);
                String url;
                if (data.optBoolean("w_after_number", false))
                    url = baseUrl + "/" + week + "/" + letter + "/" + letter + paddedNumber + ".htm";
                else
                    url = baseUrl + "/" + letter + "/" + week + "/" + letter + paddedNumber + ".htm";

                Document doc = Jsoup.parse(httpGet(url, schule.getData().getString("encoding")));
                Elements days = doc.select("#vertretung > p > b, #vertretung > b");
                for (Element day : days) {
                    VertretungsplanTag tag = getTagByDatum(tage, day.text());
                    tag.setStand(stand);
                    tag.setDatum(day.text());
                    Element next = null;
                    if (day.parent().tagName().equals("p")) {
                        next = day.parent().nextElementSibling().nextElementSibling();
                    } else
                        next = day.parent().select("p").first().nextElementSibling();
                    if (next.className().equals("subst")) {
                        //Vertretungstabelle
                        if (next.text().contains("Vertretungen sind nicht freigegeben"))
                            continue;
                        parseVertretungsplanTable(next, data, tag);
                    } else {
                        //Nachrichten
                        parseNachrichten(next, data, tag);
                        next = next.nextElementSibling().nextElementSibling();
                        parseVertretungsplanTable(next, data, tag);
                    }
                    writeTagByDatum(tage, tag);
                }

                classNumber++;
            }
        } else {
            String url;
            if (data.optBoolean("w_after_number", false))
                url = baseUrl + "/" + week + "/" + letter + "/" + letter + "00000.htm";
            else
                url = baseUrl + "/" + letter + "/" + week + "/" + letter + "00000.htm";
            Document doc = Jsoup.parse(httpGet(url, schule.getData().getString("encoding")));
            Elements days = doc.select("#vertretung > p > b, #vertretung > b");
            for (Element day : days) {
                VertretungsplanTag tag = getTagByDatum(tage, day.text());
                tag.setStand(stand);
                tag.setDatum(day.text());
                Element next = null;
                if (day.parent().tagName().equals("p")) {
                    next = day.parent().nextElementSibling().nextElementSibling();
                } else
                    next = day.parent().select("p").first().nextElementSibling();
                if (next.className().equals("subst")) {
                    //Vertretungstabelle
                    if (next.text().contains("Vertretungen sind nicht freigegeben"))
                        continue;
                    parseVertretungsplanTable(next, data, tag);
                } else {
                    //Nachrichten
                    parseNachrichten(next, data, tag);
                    next = next.nextElementSibling().nextElementSibling();
                    parseVertretungsplanTable(next, data, tag);
                }
                tage.add(tag);
            }
        }
        v.setTage(tage);
    }
    return v;
}