Examples of Elements


Examples of org.jsoup.select.Elements

   * Transfers styles from the <code>cssstyle</code> attribute to the <code>style</code> attribute.
   *
   * @param doc the html document
   */
  private void applyStyles(Document doc) {
    Elements allStyledElements = doc.getElementsByAttribute(CSS_STYLE);

    for (Element e : allStyledElements) {
      String newStyle = e.attr(CSS_STYLE);
      String oldStyle = e.attr(STYLE_ATTR);
      e.attr(STYLE_ATTR, (newStyle + "; " + oldStyle).replace(";;", ";"));
View Full Code Here

Examples of org.jsoup.select.Elements

    String trimmedStylesheet = stylesheet.replaceAll("\n", "").replaceAll("/\\*.*?\\*/", "").replaceAll(" +", " ");
    String styleRules = trimmedStylesheet.trim(), delims = "{}";
    StringTokenizer st = new StringTokenizer(styleRules, delims);
    while (st.countTokens() > 1) {
      String selector = st.nextToken(), properties = st.nextToken();
      Elements selectedElements = doc.select(selector);
      for (Element selElem : selectedElements) {
        String oldProperties = selElem.attr(CSS_STYLE);
        selElem.attr(CSS_STYLE,
            oldProperties.length() > 0 ? concatenateProperties(
                oldProperties, properties) : properties);
View Full Code Here

Examples of org.jsoup.select.Elements

            // fsyprint("Fetching %s...", url);
            String last = "";
            final String out = Constants.DATA_PATH + "playlist/"
                + playListName + ".plist";
            final Document doc = Jsoup.connect(url).get();
            final Elements links = doc.select("a[href]");
            final File playListOut = new File(out);
            final FileOutputStream fos = new FileOutputStream(
                playListOut);
            final BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(fos));
            final String header = "Title, Artist, Time, Date Added, User, Album, ALBUMART_INDEX, link";
            int iterations = 0;
            final ImporterWidget importWidget = UISession
                .getImporterWidget();
            final DiscoWidget discoWidget = UISession
                .getDiscoWidget();
            bw.write(header);
            bw.newLine();
            for (final Element link : links) {
              if (((importWidget != null) && importWidget
                  .isOpen())
                  || ((discoWidget != null) && discoWidget
                      .isOpen())) {
                if ((discoWidget != null)
                    && (discoWidget.getDiscoProgressBar() != null)) {

                  iterations += 1;

                  final int percent = (int) ((iterations * 100.0f) / links
                      .size());

                  discoWidget.getDiscoProgressBar().setValue(
                      percent);
                  PlayListUtils.disableDiscoInterface();
                } else if ((importWidget != null)
                    && (importWidget.getImportProgressBar() != null)) {
                  iterations += 1;

                  final int percent = (int) ((iterations * 100.0f) / links
                      .size());

                  importWidget.getImportProgressBar()
                      .setValue(percent);
                  PlayListUtils.disableImporterInterface();
View Full Code Here

Examples of org.jsoup.select.Elements

  String timestamp = doc.select("span.js-short-timestamp").first().attr("data-time");
  Date created_at = new Date();
  created_at.setTime(Long.parseLong(timestamp) * 1000);
  status.addProperty("created_at", date_fmt.format(created_at));

  Elements js_stats_retweets = doc.select("li.js-stat-retweets");
  if (!js_stats_retweets.isEmpty()) {
      status.addProperty("retweeted", true);
      String count = js_stats_retweets.select("strong").first().text();
      status.addProperty("retweet_count", Long.parseLong(count));
  } else {
      status.addProperty("retweeted", false);
      status.addProperty("retweet_count", 0);
  }
  Elements js_stats_favs = doc.select("li.js-stat-favorites");
  status.addProperty("favorited", !js_stats_favs.isEmpty());
     

  // User subfield
  JsonObject user = new JsonObject();
  String user_id = tweet_div.attr("data-user-id");
  user.addProperty("id_str", user_id);
  user.addProperty("id", Long.parseLong(user_id));
  String screen_name = tweet_div.attr("data-screen-name");
  user.addProperty("screen_name", screen_name);
  String user_name = tweet_div.attr("data-name");
  user.addProperty("name", user_name);
 
  status.add("user", user);
 
  // Geo information
  Elements tweet_loc = doc.select("a.tweet-geo-text");
  if (!tweet_loc.isEmpty()) {
      JsonObject location = new JsonObject();
      Element loc = tweet_loc.first();
      // Adding http to avoid malformed URL exception
      URL url = new URL("http:" + loc.attr("href"));
      Map<String, String> query_params = HTMLStatusExtractor.splitQuery(url);
      // Loop over possible query parameters
      // http://asnsblues.blogspot.ch/2011/11/google-maps-query-string-parameters.html
View Full Code Here

Examples of org.jsoup.select.Elements

        reportBuilder.generateReports();

        File input = new File(rd, "tag1.html");
        Document doc = Jsoup.parse(input, "UTF-8", "");
        assertThat(fromClass("doc-string",doc).get(0).text(),is("X _ X O X O _ O X"));
        Elements tableCells = doc.getElementsByClass("stats-table").get(0).getElementsByTag("tr").get(2).getElementsByTag("td");
        assertEquals("@tag1",tableCells.get(0).text());
        assertEquals("1",tableCells.get(1).text());
        assertEquals("1",tableCells.get(2).text());
        assertEquals("0",tableCells.get(3).text());
        assertEquals("2",tableCells.get(4).text());
        assertEquals("2",tableCells.get(5).text());
        assertEquals("0",tableCells.get(6).text());
        assertEquals("0",tableCells.get(7).text());
        assertEquals("0",tableCells.get(8).text());
        assertEquals("106 ms",tableCells.get(9).text());
        assertEquals("passed",tableCells.get(10).text());
    }
View Full Code Here

Examples of org.jsoup.select.Elements

        assertThat("stats-duration", fromId("stats-duration-Account Holder withdraws cash", doc).text(), is("112 ms"));
        assertNotNull(fromId("stats-duration-Account Holder withdraws cash", doc));
    }

    private void assertFeatureContent(Document doc) {
        Elements elements = doc.select("div.passed");

        assertThat("feature-keyword", elements.select("div.feature-line span.feature-keyword").first().text(), is("Feature:"));
        assertThat("feature-text", elements.select("div.feature-line").first().text(), is("Feature: Account Holder withdraws cash"));
        assertThat("feature-description", doc.select("div.feature-description").first().text(),
                is("As a Account Holder I want to withdraw cash from an ATM So that I can get money when the bank is closed"));
        assertThat("scenario-background-keyword", doc.select("div.passed span.scenario-keyword").first().text(), is("Background:"));
        assertThat("scenario-background-name", doc.select("div.passed span.scenario-name").first().text(), is("Activate Credit Card"));

        elements = doc.select("div.passed span.step-keyword");
        List<String> backgroundStepKeywords = new ArrayList<String>();
        List<String> firstScenarioStepKeywords = new ArrayList<String>();
        for (Element element : elements) {
            int index = elements.indexOf(element);
            if (index < 3) {
                backgroundStepKeywords.add(element.text());
            } else if (index >= 3 && index < 10) {
                firstScenarioStepKeywords.add(element.text());
            } else {
                break;
            }
        }
        assertThat("Background step keywords must be same", backgroundStepKeywords, is(Arrays.asList(new String[] {"Given", "When", "Then"})));
        assertThat("First scenario step keywords must be same", firstScenarioStepKeywords,
                is(Arrays.asList(new String[] {"Given", "And", "And", "When", "Then", "And", "And"})));

        elements = doc.select("div.passed span.step-name");
        List<String> backgroundStepNames = new ArrayList<String>();
        List<String> firstScenarioStepNames = new ArrayList<String>();
        for (Element element : elements) {
            int index = elements.indexOf(element);
            if (index < 3) {
                backgroundStepNames.add(element.text());
            } else if (index >= 3 && index < 10) {
                firstScenarioStepNames.add(element.text());
            } else {
                break;
            }
        }
        assertThat("Background step names must be same", backgroundStepNames,
                is(Arrays.asList(new String[] {
                        "I have a new credit card",
                        "I confirm my pin number",
                        "the card should be activated"})));
        assertThat("First scenario step names must be same", firstScenarioStepNames,
                is(Arrays.asList(new String[] {
                        "the account balance is 100",
                        "the card is valid",
                        "the machine contains 100",
                        "the Account Holder requests 10",
                        "the ATM should dispense 10",
                        "the account balance should be 90",
                        "the card should be returned"})));

        elements = doc.select("div.passed span.step-duration");
//        assertFalse("step durations must not be empty", elements.isEmpty());
        List<String> stepDurations = new ArrayList<String>();
        for (Element element : elements) {
            stepDurations.add(element.text());
            int index = elements.indexOf(element);
            if (index >= 10) break;
        }
        assertThat("Step durations must be same", stepDurations,
                is(Arrays.asList(new String [] {"107 ms", "0 ms", "0 ms", "0 ms", "0 ms", "0 ms", "0 ms", "3 ms", "0 ms", "0 ms", "0 ms"})));
    }
View Full Code Here

Examples of org.jsoup.select.Elements

            // print("Fetching %s...", url);
            String last = "";
            final String out = Constants.DATA_PATH + "playlist/"
                + playListName + ".plist";
            final Document doc = Jsoup.connect(url).get();
            final Elements links = doc.select("iframe");

            final File playListOut = new File(out);
            final FileOutputStream fos = new FileOutputStream(
                playListOut);
            final BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(fos));
            final String header = "Title, Artist, Time, Date Added, User, Album, ALBUMART_INDEX, link";
            bw.write(header);
            bw.newLine();
            int iterations = 0;
            for (final Element link : links) {
              if (UISession.getImporterWidget().isOpen()) {
                if (UISession.getImporterWidget()
                    .getImportProgressBar() != null) {

                  iterations += 1;

                  final int percent = (int) ((iterations * 100.0f) / links
                      .size());
                  UISession.getImporterWidget()
                  .getImportProgressBar()
                      .setValue(percent);
                  PlayListUtils.disableImporterInterface();
View Full Code Here

Examples of org.jsoup.select.Elements

            // print("Fetching %s...", url);
            String last = "";
            final String out = Constants.DATA_PATH + "playlist/"
                + playListName + ".plist";
            final Document doc = Jsoup.connect(url).get();
            final Elements links = doc.select("a[href]");
            final File playListOut = new File(out);
            final FileOutputStream fos = new FileOutputStream(
                playListOut);
            final BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(fos));
            final String header = "Title, Artist, Time, Date Added, User, Album, ALBUMART_INDEX, link";
            bw.write(header);
            bw.newLine();
            int iterations = 0;
            for (final Element link : links) {
              if (UISession.getImporterWidget().isOpen()) {
                if (UISession.getImporterWidget()
                    .getImportProgressBar() != null) {

                  iterations += 1;

                  final int percent = (int) ((iterations * 100.0f) / links
                      .size());
                  UISession.getImporterWidget()
                      .getImportProgressBar()
                  .setValue(percent);
                  PlayListUtils.disableImporterInterface();
View Full Code Here

Examples of org.jsoup.select.Elements

    return content.toString();
  }

  public void transformString(String channelString) {
    Document doc = Jsoup.parse(channelString);
    Elements tmp;
    tmp = doc.select("alias");
    if (tmp != null) {
      this.alias = (tmp.text());
    }
    tmp = doc.select("thumbImageUrl");
    if (tmp != null) {
      this.thumbImageUrl = (new Text(tmp.text()));
    }
    tmp = doc.select("title");
    if (tmp != null) {
      this.title = (new Text(tmp.text()));
    }
  }
View Full Code Here

Examples of org.jsoup.select.Elements

    }

    if (doc != null) {
      float tmpN, tmpH, tmpL;
      String msgBody = "";
      Elements ele = doc.getElementById("GridView1")
          .getElementsContainingOwnText("人民币账户白银").first()
          .siblingElements();
      tmpN = toFloat(ele.get(3).text());
      tmpH = toFloat(ele.get(6).text()) - 0.02f;
      tmpL = toFloat(ele.get(7).text()) - 0.02f;

      if (action == null || action.equals("")) {

        if (dm.getNow() == 0) {// 如果为空,第一次,保存值
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.