Ejemplo n.º 1
1
 public void scrapBlogPost(String href, BlogPost ourCopy, boolean commentsOnly, String marker)
     throws IOException {
   Document document;
   try {
     document = Jsoup.connect(href).get();
   } catch (IOException e) {
     try {
       Thread.sleep(2000);
     } catch (InterruptedException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }
     document = Jsoup.connect(href).get();
   }
   if (ourCopy == null) ourCopy = new BlogPost();
   BlogPost post = parser.parseBlogPost(document, ourCopy);
   List<BlogComment> comments = parser.parseBlogComments(document);
   if (comments != null && !comments.isEmpty()) {
     post.setComments(comments);
     post.setCommentCount(comments.size());
   } else {
     post.setCommentCount(0);
   }
   post.setUrl(href);
   post.setMarker(marker);
   repository.save(post);
 }
Ejemplo n.º 2
0
  public static String getCSSSource(String htmlSource) throws Exception {
    Document htmlDocument = Jsoup.parse(htmlSource);

    Elements elements = htmlDocument.select("link[type=text/css]");

    StringBuilder sb = new StringBuilder();

    for (Element element : elements) {
      String href = element.attr("href");

      if (!href.contains(PropsValues.PORTAL_URL)) {
        href = PropsValues.PORTAL_URL + href;
      }

      Connection connection = Jsoup.connect(href);

      Document document = connection.get();

      sb.append(document.text());

      sb.append("\n");
    }

    return sb.toString();
  }
Ejemplo n.º 3
0
  /**
   * Gets the content of the article, and creates the final section for the generated report (html)
   *
   * @param aLink
   * @return
   */
  public static String getArticleContent(String aLink, ArticleBodyParser parser) {
    Document doc = null;
    String htmltext = "";
    if (Objects.nonNull(aLink) && !aLink.isEmpty()) {
      try {
        doc =
            Jsoup.connect(aLink)
                .header("Accept-Encoding", "gzip, deflate")
                .userAgent(userAgent)
                .timeout(6000)
                .followRedirects(true)
                .maxBodySize(0)
                .get();
      } catch (IOException e) {
        LOGGER.log(
            Level.WARNING, "Error connecting, while fetching the article with link " + aLink);
      }
      if (doc != null) {
        Element title = doc.getElementsByTag("title").first();
        Element mainArticle = parser.parseArticleFromDoc(doc);
        if (Objects.nonNull(title) && Objects.nonNull(mainArticle)) {
          htmltext =
              HtmlContentWriterUtil.generateArticleHtml(
                  title.html(), aLink, Jsoup.clean(mainArticle.html(), Whitelist.basic()));

        } else {
          LOGGER.warning("We could not fetch the title and main body for link: " + aLink);
        }
      }
    }
    return htmltext;
  }
Ejemplo n.º 4
0
  public static boolean isShotbowDonor(String user) throws IOException {

    Document doc =
        Jsoup.connect("https://shotbow.net/forum/search").userAgent(WebUtils.USER_AGENT).get();
    String xfToken = doc.select("input[name=_xfToken]").val();

    RequestSettings request = new RequestSettings();

    request.setGzip(false);
    request.setUrl("https://shotbow.net/forum/search/search");
    request.setHost("shotbow.net");
    request.setOrigin("https://www.shotbow.net");
    request.setReferer("https://shotbow.net/forum/portal/");

    request.addParameter("keywords", user);
    request.addParameter("users", "");
    request.addParameter("date", "");
    request.addParameter("_xfToken", xfToken);

    String response = RequestUtils.excuteSpecialPost(request);

    Document doc1 = Jsoup.parse(response);

    for (Element e : doc1.select("li.userResult")) {

      if (e.select("a.username").first().text().equalsIgnoreCase(user)) {
        return !e.select("div.userTitle").first().text().equalsIgnoreCase("Regular Member");
      }
    }

    return false;
  }
  @Test
  public void equalsWithUnequalElementReturnsFalse() {
    TypedElement input1 = new TypedElement(Jsoup.parse("<h1/>"));
    TypedElement input2 = new TypedElement(Jsoup.parse("<h2/>"));

    assertThat(input1.equals(input2), is(false));
  }
Ejemplo n.º 6
0
  /*
   * I haven't found a direct way of extracting the download URL of a Mixcloud track.
   * Mixcloud's track preview URLs and full download URLs are similar. The preview URL for
   * a Mixcloud track is simple to extract.
   *
   * This method replaces the "previews" part of the preview URL with "cloudcasts/originals" and then
   * cycles through all of Mixcloud's stream servers until the download URL is found.
   *
   * Similarity between Mixcloud preview URL and full download URL:
   * http://stream8.mxcdn.com/previews/9/6/a/e/93a8-2d77-4573-85c5-68bfb679d9bc.mp3 - preview URL
   * http://stream11.mxcdn.com/cloudcasts/originals/9/6/a/e/93a8-2d77-4573-85c5-68bfb679d9bc.mp3 - download URL
   */
  private String generateStreamURL() throws IOException {
    String downloadUrl = this.getPreviewURL().replaceAll("previews", "cloudcasts/originals");

    try {
      @SuppressWarnings("unused")
      Response res =
          Jsoup.connect(downloadUrl)
              .ignoreContentType(true)
              .userAgent("Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0")
              .execute();
      return downloadUrl;
    } catch (HttpStatusException firstAttempt) {
      int serversToCycle = 30;
      for (int i = 1; i <= serversToCycle; ) {
        try {
          String cycledUrl = downloadUrl.replaceAll("stream[0-9]+", ("stream" + i));

          Response res =
              Jsoup.connect(cycledUrl)
                  .ignoreContentType(true)
                  .userAgent("Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0")
                  .execute();
          if (res.parse().toString().length() < 2000) i++;
          else return cycledUrl;
        } catch (HttpStatusException cycledAttempt) {
          i++;
        }
      }
    }

    return null;
  }
 @Override
 public void populateMetaData(MetaData metaData) throws MetaDataException {
   Document doc;
   try {
     if (method.equals("GET")) {
       doc = Jsoup.connect(url).get();
     } else if (method.equals("POST")) {
       doc = Jsoup.connect(url).data(requestData).post();
     } else {
       throw new MetaDataException("Unsupported HTML access method: " + method);
     }
     for (MetaDataAttribute attribute : attributes) {
       Elements elements = doc.select(attribute.getQuery());
       if (elements.size() > 0) {
         String sValue = elements.get(0).text();
         Object oValue = attribute.getValueMapper().parse(sValue);
         metaData.put(attribute.getName(), oValue);
       }
     }
   } catch (IOException e) {
     throw new MetaDataException(e);
   } catch (ValueMapperException e) {
     throw new MetaDataException(e);
   }
 }
Ejemplo n.º 8
0
 private Response postToLogin(String username, String password, String[] captchaData)
     throws ConnectionException {
   try {
     Map<String, String> data = new HashMap<>();
     Document loginDocument = Jsoup.connect(Endpoints.LOGIN_URL.url()).get();
     Element loginForm = loginDocument.getElementById("loginForm");
     for (Element input : loginForm.getElementsByTag("input")) {
       data.put(input.attr("name"), input.attr("value"));
     }
     Date now = new Date();
     data.put("timezone_field", new SimpleDateFormat("XXX").format(now).replace(':', '|'));
     data.put("username", username);
     data.put("password", password);
     data.put("js_time", String.valueOf(now.getTime() / 1000));
     if (captchaData.length > 0) {
       data.put("hip_solution", captchaData[0]);
       data.put("hip_token", captchaData[1]);
       data.put("fid", captchaData[2]);
       data.put("hip_type", "visual");
       data.put("captcha_provider", "Hip");
     } else {
       data.remove("hip_solution");
       data.remove("hip_token");
       data.remove("fid");
       data.remove("hip_type");
       data.remove("captcha_provider");
     }
     return Jsoup.connect(Endpoints.LOGIN_URL.url()).data(data).method(Method.POST).execute();
   } catch (IOException e) {
     throw ExceptionHandler.generateException("While submitting credentials", e);
   }
 }
Ejemplo n.º 9
0
  public static boolean isBukkit(String user) throws IOException {

    Document doc = Jsoup.connect("https://www.bukkit.org/").userAgent(WebUtils.USER_AGENT).get();
    String xfToken = doc.select("input[name=_xfToken]").val();

    RequestSettings request = new RequestSettings();

    request.setGzip(false);
    request.setUrl("http://bukkit.org/search/search");
    request.setHost("bukkit.org");
    request.setOrigin("http://bukkit.org");
    request.setReferer("http://bukkit.org/forums/");

    request.addParameter("keywords", user);
    request.addParameter("users", "");
    request.addParameter("date", "");
    request.addParameter("_xfToken", xfToken);

    String response = RequestUtils.excuteSpecialPost(request);

    Document doc1 = Jsoup.parse(response);

    for (Element e : doc1.select(".username")) {

      if (e.text().equalsIgnoreCase(user)) {
        return true;
      }
    }

    return false;
  }
Ejemplo n.º 10
0
 private static String[] crop(String startstring) {
   if (startstring.length() > 0) {
     String[] splitted = startstring.split("</b>");
     return new String[] {Jsoup.parse(splitted[0]).text().trim(), Jsoup.parse(splitted[1]).text()};
   } else {
     return new String[] {"", ""};
   }
 }
Ejemplo n.º 11
0
 @Test
 public void testIsValid() {
   String ok = "<p>Test <b><a href='http://example.com/'>OK</a></b></p>";
   String nok1 = "<p><script></script>Not <b>OK</b></p>";
   String nok2 = "<p align=right>Test Not <b>OK</b></p>";
   assertTrue(Jsoup.isValid(ok, Whitelist.basic()));
   assertFalse(Jsoup.isValid(nok1, Whitelist.basic()));
   assertFalse(Jsoup.isValid(nok2, Whitelist.basic()));
 }
Ejemplo n.º 12
0
  @Test
  public void testBrHasSpace() {
    Document doc = Jsoup.parse("<p>Hello<br>there</p>");
    assertEquals("Hello there", doc.text());
    assertEquals("Hello there", doc.select("p").first().ownText());

    doc = Jsoup.parse("<p>Hello <br> there</p>");
    assertEquals("Hello there", doc.text());
  }
Ejemplo n.º 13
0
 /** Turns a HTML document back into a set of text, elements, annotations. */
 public static UnrenderedBlip unrender(final String content) {
   final StringBuilder sb = new StringBuilder();
   final Map<Integer, com.google.wave.api.Element> elements = Maps.newHashMap();
   final Annotations annotations = new Annotations();
   // Sanitized
   final String safe = Jsoup.clean(content, Whitelist.basic());
   final Document doc = Jsoup.parse(safe);
   unrender(doc.body(), sb, elements, annotations);
   return new UnrenderedBlip(sb.toString(), elements, annotations);
 }
Ejemplo n.º 14
0
  public void testWrite(String design, T expected, boolean writeData) {
    String written = write(expected, writeData);

    Element producedElem = Jsoup.parse(written).body().child(0);
    Element comparableElem = Jsoup.parse(design).body().child(0);

    String produced = elementToHtml(producedElem);
    String comparable = elementToHtml(comparableElem);

    Assert.assertEquals(comparable, produced);
  }
Ejemplo n.º 15
0
  @Test
  public void testById() {
    Elements els =
        Jsoup.parse("<div><p id=foo>Hello</p><p id=foo>Foo two!</p></div>").select("#foo");
    assertEquals(2, els.size());
    assertEquals("Hello", els.get(0).text());
    assertEquals("Foo two!", els.get(1).text());

    Elements none = Jsoup.parse("<div id=1></div>").select("#foo");
    assertEquals(0, none.size());
  }
Ejemplo n.º 16
0
    @Override
    protected String doInBackground(Void... params) {
      String html = "";
      try {
        Connection.Response loginForm;
        loginForm =
            Jsoup.connect("https://ta.yrdsb.ca/yrdsb/").method(Connection.Method.GET).execute();

        // Login to page using user/pass entered in MainActivity
        Document document =
            Jsoup.connect("https://ta.yrdsb.ca/yrdsb/")
                .data("cookieexists", "false")
                .data("username", MainActivity.usernameString)
                .data("password", MainActivity.passwordString)
                .data("submit", "Login")
                .cookies(loginForm.cookies())
                .post();

        // Convert document into string for easier processing
        html = document.toString();

        Document doc = Jsoup.parse(html);
        // for (int x = 0; x < doc.select("[width=85%], [border=0], [cellspacing=0],
        // [cellpadding=5]").size(); x++){
        System.out.println(
            doc.select("[width=85%], [border=0], [cellspacing=0], [cellpadding=5]")
                .select("tr")
                .size());
        // System.out.println(doc.select("[width=85%], [border=0], [cellspacing=0],
        // [cellpadding=5]").select("tr").get(5));
        // }

        // Prepare array to store grades
        grades = new ArrayList<>();
        courses = new ArrayList<>();

        // Regex to search html string for grades, then add to array
        Pattern p = Pattern.compile("current mark\\s?=\\s?(\\d+\\.?\\d*)");
        Matcher m = p.matcher(html);
        while (m.find()) {
          grades.add(new Double(m.group(1)));
        }

        Pattern p1 = Pattern.compile("([a-zA-Z]{3}[0-9]{1}[a-zA-Z]{1}[0-9]{1})");
        Matcher m1 = p1.matcher(html);
        while (m1.find()) {
          courses.add(new String(m1.group(1)));
        }

      } catch (IOException e) {
        e.printStackTrace();
      }
      return html;
    }
Ejemplo n.º 17
0
 public static final String getAllTopicArtileUrl(String url) throws IOException {
   String topic = null;
   Document doc = Jsoup.connect(url).get();
   Elements blocks = doc.select("a");
   topic = "http://bbs.nju.edu.cn/" + blocks.get(blocks.size() - 1).attr("href");
   String nextContent = Jsoup.connect(topic).get().toString();
   topic =
       nextContent.substring(nextContent.indexOf("url=") + 4, nextContent.indexOf(".A\" />") + 2);
   topic = "http://bbs.nju.edu.cn/" + topic.replace("amp;", "");
   return topic;
 }
  public void parsingHTML(String urlPath) {
    String price = "";
    try {
      URL url = new URL(urlPath);
      Document doc;
      if (server_down) {
        doc = Jsoup.parse(url.openStream(), "UTF-8", urlPath);
      } else {
        doc = Jsoup.parse(url.openStream(), "ISO-8859-1", urlPath);
      }
      // Document doc = Jsoup.parse(url, 2000);
      Elements trs = doc.select("tr");

      for (int a = 2; a <= 6; a++) {
        Elements tds = trs.get(a).select("td");
        for (int i = 1; i <= 5; i++) {
          switch (a) {
              // DATUM
            case 2:
              foodDayList.get(i - 1).setDate(tds.get(i).select("td").text());
              // Log.v(TAG, "date: " + tds.get(i).select("td").text());
              break;
              // ESSEN 1 DESC
            case 3:
              foodDayList.get(i - 1).setEssen1Desc(tds.get(i).select("td").text());
              break;
            case 4:
              // TODO: ESSEN 1 PREIS
              price = "";
              for (int p = 0; p < 4; p++) {
                price += tds.get((i - 1) * 4 + p).text();
              }
              foodDayList.get(i - 1).setEssen1Price(price);
              break;
            case 5:
              // ESSEN 2 DESC
              foodDayList.get(i - 1).setEssen2Desc(tds.get(i).select("td").text());
              break;
            case 6:
              // TODO ESSEN 2 PREIS
              price = "";
              for (int p = 0; p < 4; p++) {
                price += tds.get((i - 1) * 4 + p).text();
              }
              foodDayList.get(i - 1).setEssen2Price(price);
              break;
          }
        }
      }
    } catch (Exception e) {
      Log.e(TAG, e.getMessage());
    }
  }
Ejemplo n.º 19
0
 @Test
 public void test03() throws Exception {
   Connection connect = Jsoup.connect("http://www.jb51.net/article/16829.htm");
   Connection.Response execute = connect.execute();
   String body = execute.body();
   System.out.println(body);
   Document parse = Jsoup.parse(body);
   Elements elements = parse.select("[src$=.gif]");
   for (Element element : elements) {
     System.out.println(element.attr("src"));
   }
 }
Ejemplo n.º 20
0
  @Test
  public void parsesUnterminatedTag() {
    String h1 = "<p";
    Document doc = Jsoup.parse(h1);
    assertEquals(1, doc.getElementsByTag("p").size());

    String h2 = "<div id=1<p id='2'";
    doc = Jsoup.parse(h2);
    Element d = doc.getElementById("1");
    assertEquals(1, d.children().size());
    Element p = doc.getElementById("2");
    assertNotNull(p);
  }
Ejemplo n.º 21
0
 /**
  * get the content in the html without tags
  *
  * @param url
  * @return
  * @throws IOException
  */
 public String getHTMLContent(String url) throws IOException {
   try {
     Document doc = Jsoup.connect(url).get();
     // Remove html white spaces
     doc.select(":containsOwn(\u00a0)").remove();
     // Remove remaining HTML code
     String content = doc.text();
     content = Jsoup.clean(content, Whitelist.relaxed());
     return content;
   } catch (SocketTimeoutException e) {
     System.out.println("Time out exception, url: " + url);
     return "";
   }
 }
Ejemplo n.º 22
0
  @Test
  public void testGetElementById() {
    Document doc = Jsoup.parse(reference);
    Element div = doc.getElementById("div1");
    assertEquals("div1", div.id());
    assertNull(doc.getElementById("none"));

    Document doc2 =
        Jsoup.parse("<div id=1><div id=2><p>Hello <span id=2>world!</span></p></div></div>");
    Element div2 = doc2.getElementById("2");
    assertEquals("div", div2.tagName()); // not the span
    Element span = div2.child(0).getElementById("2"); // called from <p> context should be span
    assertEquals("span", span.tagName());
  }
Ejemplo n.º 23
0
  @Override
  public List<TweetOut> getTweetOutList(User user) throws DAOException {
    List<TweetOut> lstTweetOut = new ArrayList<>();
    try {
      ResultSet resultSet =
          this.executeQuery(
              SQL_SELECTTWEETOUT,
              false,
              user.getUserId(),
              user.getUserId(),
              user.getUserId(),
              user.getUserId(),
              user.getUserId(),
              user.getUserId());
      Pattern pat = Pattern.compile("@([\\w]+)");
      while (resultSet.next()) {
        EntityMapping<TweetOut> EntityMapping = new EntityMapping<>(TweetOut.class);
        try {
          TweetOut tmpTweetOut = EntityMapping.getMapping(resultSet);
          Matcher match = pat.matcher(tmpTweetOut.getBody());

          if (match.find()) {
            String action = match.group(1);
            DAOUser daoUser = new DAOUser(DAOFactory.getInstance());
            User user1 = daoUser.searchByUserName(action);
            tmpTweetOut.setBody(
                Jsoup.parse(tmpTweetOut.getBody())
                    .text()
                    .replace(
                        "@" + action,
                        "<a class=\"\" href=\"/User?id="
                            + user1.getUserId()
                            + "\"><strong class=\"center-middle-txt\">@"
                            + action
                            + "</strong></a>"));
          } else {
            tmpTweetOut.setBody(Jsoup.parse(tmpTweetOut.getBody()).text());
          }
          lstTweetOut.add(tmpTweetOut);
        } catch (Exception e) {
          throw new DAOException(e);
        }
      }
    } catch (Exception e) {
      throw new DAOException(e);
    } finally {
      this.CloseConnection();
    }
    return lstTweetOut;
  }
Ejemplo n.º 24
0
  @Override
  public void endElement(String uri, String localName, String qName) throws SAXException {
    if (inChannel) {
      if (inTitle) {
        feeds.setTitle(temp);
        inTitle = false;
      } else if (inLink) {
        feeds.setLink(temp);
        inLink = false;
      } else if (inDesc) {
        Document doc = Jsoup.parseBodyFragment(temp);
        Element body = doc.body();
        feeds.setDescription(body.text());
        inDesc = false;
      } else if (inLanguage) {
        feeds.setLanguage(temp);
        inLanguage = false;
      }

    } else if (inItem) {
      if (inTitle) {
        item.setTitle(temp);
        inTitle = false;
      } else if (inLink) {
        item.setLink(temp);
        inLink = false;
      } else if (inDesc) {
        Document doc = Jsoup.parseBodyFragment(temp);
        Element body = doc.body();
        item.setDescription(body.text());
        inDesc = false;
      } else if (inPubdate) {
        item.setPubdate(temp);
        inPubdate = false;
      } else if (inGuid) {
        item.setGuid(temp);
        inGuid = false;
      }
    }
    if (qName.equalsIgnoreCase("channel")) {
      if (feeds != null) {
        feeds.setItems(itemsList);
        feedsList.add(feeds);
        itemsList = new ArrayList<RSSItem>();
      }
    }
    if (qName.equalsIgnoreCase("item")) {
      if (item != null) itemsList.add(item);
    }
  }
Ejemplo n.º 25
0
  @Test
  public void testByTag() {
    // should be case insensitive
    Elements els =
        Jsoup.parse("<div id=1><div id=2><p>Hello</p></div></div><DIV id=3>").select("DIV");
    assertEquals(3, els.size());
    assertEquals("1", els.get(0).id());
    assertEquals("2", els.get(1).id());
    assertEquals("3", els.get(2).id());

    Elements none =
        Jsoup.parse("<div id=1><div id=2><p>Hello</p></div></div><div id=3>").select("span");
    assertEquals(0, none.size());
  }
Ejemplo n.º 26
0
  @Test
  public void testByClass() {
    Elements els =
        Jsoup.parse("<p id=0 class='ONE two'><p id=1 class='one'><p id=2 class='two'>")
            .select("P.One");
    assertEquals(2, els.size());
    assertEquals("0", els.get(0).id());
    assertEquals("1", els.get(1).id());

    Elements none = Jsoup.parse("<div class='one'></div>").select(".foo");
    assertEquals(0, none.size());

    Elements els2 = Jsoup.parse("<div class='One-Two'></div>").select(".one-two");
    assertEquals(1, els2.size());
  }
Ejemplo n.º 27
0
 @Override
 public void onTaskFinished(String response) {
   progress.cancel();
   if (response == null) {
     Toast.makeText(this, "An error has occured.", Toast.LENGTH_LONG).show();
     onResume();
     return;
   } else if (response == LocationHelper.LOCATION_FAILED) {
     Toast.makeText(this, "Unable to determine your location.", Toast.LENGTH_LONG).show();
     onResume();
     return;
   }
   Document doc = Jsoup.parse(response);
   if (doc.title().contains("Route")) {
     RouteActivity.start(HomeActivity.this, response);
   } else if (doc.title().contains("Stop")) {
     System.out.println(doc.title());
   } else if (response.contains("Did you mean?")
       && (response.contains("class=\"routeList\"")
           || response.contains("class=\"ambiguousLocations\""))) {
     new DidYouMeanDialog()
         .newInstance(this, response)
         .show(getSupportFragmentManager(), "com.steelhawks.hawkscout.DID_YOU_MEAN_DIALOG");
   } else if (response.contains("<h3>Nearby Stops:</h3>")) {
     NearbyStopsActivity.start(this, response);
   } else {
     new NoResultsDialog()
         .show(getSupportFragmentManager(), "com.steelhawks.hawkscout.NO_RESULTS");
     onResume();
   }
 }
Ejemplo n.º 28
0
 public Item(
     String source,
     String link,
     String title,
     String description,
     Date datePublication,
     List enclosure) {
   try {
     this.uri = link;
     values = new ArrayList<Prop>();
     values.add(new Prop(RSS.link, link, true, false));
     values.add(new Prop(RSS.title, title));
     values.add(new Prop(RSS.description, Jsoup.parse(description).text()));
     if (datePublication != null) {
       values.add(new Prop(RSS.getURI() + "pubDate", datePublication.toString()));
       values.add(
           new Prop(RSS.getURI() + "pubDateTime", Long.toString(datePublication.getTime())));
     }
     for (Object o : enclosure) {
       SyndEnclosureImpl e = (SyndEnclosureImpl) o;
       values.add(new Prop(RSS.image, e.getUrl(), true, false));
     }
     values.add(new Prop("http://purl.org/rss/1.0/source", source, false, false));
   } catch (NullPointerException e) {
     logger.error(e);
   }
 }
Ejemplo n.º 29
0
  public List<MenuMeal> getMenuMeals(int number) {
    Document doc = null;
    List<MenuMeal> meals = new ArrayList<>();

    try {
      doc =
          Jsoup.connect(String.format(URL, number))
              .userAgent("Chrome/49.0.2623.112")
              .referrer("https://www.google.ru/")
              .timeout(7000)
              .get();
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (doc == null) return meals;

    Elements elements = doc.select("td[width=400");

    if (!elements.isEmpty()) {
      for (Element element : elements) {
        Element parent = element.parent();
        MenuMeal menuMeal = new MenuMeal();

        menuMeal.setDescription(parent.select("div[id=ssilka]").first().text());
        String cost = parent.select("div[id=ssilka]").last().text();
        menuMeal.setCost(Integer.valueOf(cost.substring(0, cost.indexOf("-"))));

        meals.add(menuMeal);
      }
      return meals;
    } else {
      return meals;
    }
  }
Ejemplo n.º 30
-1
 @Override
 protected Object doInBackground(Object[] params) {
   try {
     Document feed =
         Jsoup.connect("https://gdata.youtube.com/feeds/api/videos/" + ID_VIDEO + "?v=2")
             .userAgent(
                 "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22")
             .timeout(60000)
             .ignoreContentType(true)
             .get();
     values.setTitleVideo(feed.getElementsByTag("title").text());
     values.setDescriptionVideo(feed.getElementsByTag("media:description").text());
     values.setLikeVideo(feed.select("yt|rating").attr("numLikes"));
     values.setDislikeVideo(feed.select("yt|rating").attr("numDislikes"));
     values.setAverageVideo(feed.select("gd|rating").attr("average"));
     values.setViewsVideo(feed.select("yt|statistics").attr("viewCount"));
     values.setDurationVideo(feed.select("yt|duration").attr("seconds"));
     values.setThumbnailVideo(feed.select("media|thumbnail").first().attr("url"));
     values.setAuthorVideo(feed.getElementsByTag("name").text());
     values.setAuthorVideoId(feed.getElementsByTag("yt:uploaderId").text());
     values.setNumberCommentsVideo(feed.select("gd|feedLink").attr("countHint"));
     values.setFeedCommentsVideo(feed.select("gd|feedLink").attr("href"));
     values.setCategoryVideo(feed.select("media|category").attr("label"));
     values.setDateVideo(feed.getElementsByTag("yt:uploaded").text());
     Document image =
         Jsoup.connect(feed.getElementsByTag("uri").text())
             .userAgent(
                 "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22")
             .timeout(60000)
             .ignoreContentType(true)
             .get();
     values.setThumbnailAuthor(image.select("media|thumbnail").attr("url"));
     if (showLog) {
       Log.d(TAG_LOG, feed.getElementsByTag("title").text());
       Log.d(TAG_LOG, feed.getElementsByTag("media:description").text());
       Log.d(TAG_LOG, feed.select("yt|rating").attr("numLikes"));
       Log.d(TAG_LOG, feed.select("yt|rating").attr("numDislikes"));
       Log.d(TAG_LOG, feed.select("gd|rating").attr("average"));
       Log.d(TAG_LOG, feed.select("yt|statistics").attr("viewCount"));
       Log.d(TAG_LOG, feed.select("yt|duration").attr("seconds"));
       Log.d(TAG_LOG, feed.select("media|thumbnail").first().attr("url"));
       Log.d(TAG_LOG, feed.getElementsByTag("name").text());
       Log.d(TAG_LOG, feed.getElementsByTag("yt:uploaderId").text());
       Log.d(TAG_LOG, feed.select("gd|feedLink").attr("countHint"));
       Log.d(TAG_LOG, feed.select("gd|feedLink").attr("href"));
       Log.d(TAG_LOG, feed.select("media|category").attr("label"));
       Log.d(TAG_LOG, feed.getElementsByTag("yt:uploaded").text());
       Log.d(TAG_LOG, image.select("media|thumbnail").attr("url"));
     }
   } catch (IOException e) {
     error = true;
     e.printStackTrace();
   }
   return null;
 }