List of usage examples for org.jsoup.nodes Element attr
public String attr(String attributeKey)
From source file:de.geeksfactory.opacclient.apis.TouchPoint.java
static List<LentItem> parse_medialist(Document doc) { List<LentItem> media = new ArrayList<>(); Elements copytrs = doc.select(".data tr"); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN); int trs = copytrs.size(); if (trs == 1) { return null; }//from w w w. j av a 2s.c o m assert (trs > 0); for (int i = 1; i < trs; i++) { Element tr = copytrs.get(i); LentItem item = new LentItem(); if (tr.text().contains("keine Daten")) { return null; } item.setTitle(tr.select(".account-display-title").select("b, strong").text().trim()); try { item.setAuthor(tr.select(".account-display-title").html().split("<br[ /]*>")[1].trim()); String[] col3split = tr.select(".account-display-state").html().split("<br[ /]*>"); String deadline = Jsoup.parse(col3split[0].trim()).text().trim(); if (deadline.contains(":")) { // BSB Munich: <span class="hidden-sm hidden-md hidden-lg">Flligkeitsdatum : </span>26.02.2016<br> deadline = deadline.split(":")[1].trim(); } if (deadline.contains("-")) { // Chemnitz: 22.07.2015 - 20.10.2015<br> deadline = deadline.split("-")[1].trim(); } try { item.setDeadline(fmt.parseLocalDate(deadline).toString()); } catch (IllegalArgumentException e1) { e1.printStackTrace(); } if (col3split.length > 1) item.setHomeBranch(col3split[1].trim()); if (tr.select("a").size() > 0) { for (Element link : tr.select("a")) { String href = link.attr("abs:href"); Map<String, String> hrefq = getQueryParamsFirst(href); if (hrefq.get("methodToCall").equals("renewal")) { item.setProlongData(href.split("\\?")[1]); item.setRenewable(true); break; } } } } catch (Exception ex) { ex.printStackTrace(); } media.add(item); } return media; }
From source file:com.mycompany.grabberrasskazov.threads.ThreadForPageSave.java
public void indexStory(String pageUrl) { try {/* w ww.j a v a 2 s . c om*/ String oldId = pageUrl.replace(GlobalVars.mainSite, ""); if (!mainBean.storyExists(oldId)) { Stories r = new Stories(); Document doc = Jsoup.connect(pageUrl) .userAgent("Opera/9.80 (X11; Linux x86_64) " + "Presto/2.12.388 Version/12.16").get(); Elements nameBlockElements = doc.select("b:containsOwn(?)"); Element nameBlock = nameBlockElements.get(0); nameBlock = nameBlock.parent().parent(); nameBlockElements = nameBlock.select("td:eq(1)"); nameBlock = nameBlockElements.get(0); String storyName = nameBlock.text(); r.setStoryName(storyName); // Start of processing writer Elements writerBlockElements = doc.select("b:containsOwn(?:)"); Element writerBlock = writerBlockElements.get(0); writerBlock = writerBlock.parent().parent(); writerBlockElements = writerBlock.select("td:eq(1)"); writerBlock = writerBlockElements.get(0); String writersUrl = writerBlock.select("a:eq(0)").attr("href"); String writersName = writerBlock.select("a:eq(0)").text(); String writersContacts = writerBlock.select("a:eq(1)").attr("href"); StoryWriters storyWriter = new StoryWriters(); storyWriter.setOldId(writersUrl); storyWriter.setWriterEmail(writersContacts); storyWriter.setWriterName(writersName); storyWriter = mainBean.saveWriter(storyWriter); Set<StoriesToWritersRelations> storiesToWritersRelationses = new HashSet<StoriesToWritersRelations>(); StoriesToWritersRelations storiesToWritersRelations = new StoriesToWritersRelations(); storiesToWritersRelations.setStories(r); storiesToWritersRelations.setStoryWriters(storyWriter); r.setStoriesToWritersRelationses(storiesToWritersRelationses); // End of processing writer Set<StoriesToCategoriessRelations> catsRelationses = new HashSet<>(); Elements katsInfo = doc.select("a[href*=ras.shtml?kat]"); for (Element kat : katsInfo) { String katId = kat.attr("href"); StoryCategories cat = mainBean.getCat(katId); StoriesToCategoriessRelations catsRelations = new StoriesToCategoriessRelations(); catsRelations.setStoryCategories(cat); catsRelations.setStories(r); catsRelationses.add(catsRelations); } r.setStoriesToCategoriessRelationses(catsRelationses); Elements textBlocks = doc.select("p[align=justify]"); Element textBlock = textBlocks.get(0); String textStr = textBlock.html(); r.setStoryText(textStr.replace("\"", "'")); r.setOldId(oldId); mainBean.saveStory(r); } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:amazonechoapi.AmazonEchoApi.java
public boolean httpLogin() { try {/*from w ww.j av a 2 s. co m*/ String output = httpGet(""); Document doc = Jsoup.parse(output); Elements forms = doc.select("form"); String action = forms.attr("action"); if (action.isEmpty()) { return false; } Elements hidden = doc.select("input[type=hidden]"); List<NameValuePair> nvps = new ArrayList<>(); nvps.add(new BasicNameValuePair("email", USERNAME)); nvps.add(new BasicNameValuePair("password", PASSWORd)); nvps.add(new BasicNameValuePair("create", "0")); for (Element el1 : hidden) { nvps.add(new BasicNameValuePair(el1.attr("name"), el1.attr("value"))); } HttpPost httpPost = new HttpPost(action); httpPost.setHeader(HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13"); httpPost.setHeader(HttpHeaders.REFERER, BASE_URL); httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse httpResponse = httpclient.execute(httpPost); httpResponse.getEntity(); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { EntityUtils.consume(entity); } System.out.println("Login successful"); return true; } catch (Exception e) { System.out.println("Login Error:" + e.getMessage()); return false; } }
From source file:org.apache.sling.hapi.client.forms.internal.FormValues.java
/** * @return/* www .ja v a 2 s. co m*/ * {@see http://www.w3.org/TR/html5/forms.html#constructing-the-form-data-set} */ private FormValues build() { for (Element input : form.select("button, input, select, textarea")) { String type = input.attr("type"); if (input.hasAttr("disabled")) continue; if (input.tagName().equalsIgnoreCase("button") && !type.equals("submit")) continue; if (input.tagName().equalsIgnoreCase("input") && (type.equals("button") || type.equals("reset"))) continue; if (type.equals("checkbox") && input.hasAttr("checked")) continue; if (type.equals("radio") && input.hasAttr("checked")) continue; if (!type.equals("image") && input.attr("name").length() == 0) continue; if (input.parents().is("datalist")) continue; if (type.equals("image") || type.equals("file")) continue; // don't support files for now String name = input.attr("name"); if (input.tagName().equalsIgnoreCase("select")) { for (Element o : input.select("option[selected]")) { if (o.hasAttr("disabled")) continue; list.add(name, new BasicNameValuePair(name, o.val())); } } else if (type.equals("checkbox") || type.equals("radio")) { String value = input.hasAttr("value") ? input.val() : "on"; list.add(name, new BasicNameValuePair(name, value)); } else { list.add(name, new BasicNameValuePair(name, input.val())); } } return this; }
From source file:com.clonescriptscrapper.crawler.CloneScriptScrapper.java
public void crawledCategories() throws URISyntaxException, IOException, InterruptedException, Exception { String url = "http://www.clonescriptdirectory.com/"; // Document doc = Jsoup.parse(fetchPage(new URI(url))); String response = ""; response = new GetRequestHandler().doGetRequest(new URL(url)); Document doc = Jsoup.parse(response); // System.out.println("---" + doc); Elements ele = doc.select("table[class=categories] tbody tr td a"); for (Element ele1 : ele) { objCategories = new Categories(); String title = ele1.text(); String href = ele1.attr("href"); System.out.println("Title : " + ele1.text()); System.out.println("Href : " + ele1.attr("href")); objCategories.setCategoryName(title); objCategories.setCategoryUrl(href); objCloneScriptDirectoryDaoImpl.insertCategoriesData(objCategories); }/*from w ww .j a v a 2 s . c o m*/ List<Future<String>> list = new ArrayList<Future<String>>(); ExecutorService executor = Executors.newFixedThreadPool(5); List<Categories> listCatogories = objCloneScriptDirectoryDaoImpl.getCategoriesDataList(); for (Categories listCatogory : listCatogories) { try { objCloneScriptDirectoryDaoImpl.updateCategoriesData(objCategories); Callable worker = new CrawlingEachUrlData(listCatogory, objCloneScriptDirectoryDaoImpl); Future<String> future = executor.submit(worker); list.add(future); } catch (Exception exx) { System.out.println(exx); } } for (Future<String> fut : list) { try { //print the return value of Future, notice the output delay in console // because Future.get() waits for task to get completed System.out.println(new Date() + "::" + fut.get()); } catch (InterruptedException | ExecutionException ep) { ep.printStackTrace(); } } //shut down the executor service now executor.shutdown(); // objcrawlingUrlData.crawlingUrlData(href); }
From source file:org.keycloak.testsuite.util.saml.RequiredConsentBuilder.java
/** * Prepares a GET/POST request for consent granting . The consent page is expected * to have at least input fields with id "kc-login" and "kc-cancel". * * @param consentPage/*from w w w . j av a 2 s. c o m*/ * @param consent * @return */ public HttpUriRequest handleConsentPage(String consentPage, URI currentURI) { org.jsoup.nodes.Document theLoginPage = Jsoup.parse(consentPage); List<NameValuePair> parameters = new LinkedList<>(); for (Element form : theLoginPage.getElementsByTag("form")) { String method = form.attr("method"); String action = form.attr("action"); boolean isPost = method != null && "post".equalsIgnoreCase(method); for (Element input : form.getElementsByTag("input")) { if (Objects.equals(input.id(), "kc-login")) { if (approveConsent) parameters.add(new BasicNameValuePair(input.attr("name"), input.attr("value"))); } else if (Objects.equals(input.id(), "kc-cancel")) { if (!approveConsent) parameters.add(new BasicNameValuePair(input.attr("name"), input.attr("value"))); } else { parameters.add(new BasicNameValuePair(input.attr("name"), input.val())); } } if (isPost) { HttpPost res = new HttpPost(currentURI.resolve(action)); UrlEncodedFormEntity formEntity; try { formEntity = new UrlEncodedFormEntity(parameters, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } res.setEntity(formEntity); return res; } else { UriBuilder b = UriBuilder.fromPath(action); for (NameValuePair parameter : parameters) { b.queryParam(parameter.getName(), parameter.getValue()); } return new HttpGet(b.build()); } } throw new IllegalArgumentException("Invalid consent page: " + consentPage); }
From source file:com.liato.bankdroid.banking.banks.Hors.java
@Override protected LoginPackage preLogin() throws BankException, IOException { urlopen = new Urllib(context); urlopen.setAllowCircularRedirects(true); response = urlopen.open("https://www.dittkort.se//q/?p=7EB4F129-0A41-417F-8FEA-51B2B75B9D24"); Document d = Jsoup.parse(response); Element e = d.getElementById("__VIEWSTATE"); if (e == null || e.attr("value") == null) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " ViewState."); }/*w ww . j av a2s . c o m*/ String viewState = e.attr("value"); e = d.getElementById("__EVENTVALIDATION"); if (e == null || e.attr("value") == null) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " EventValidation."); } String eventValidation = e.attr("value"); List<NameValuePair> postData = new ArrayList<NameValuePair>(); postData.add(new BasicNameValuePair("__EVENTTARGET", "")); postData.add(new BasicNameValuePair("__EVENTARGUMENT", "")); postData.add(new BasicNameValuePair("__VIEWSTATE", viewState)); postData.add(new BasicNameValuePair("__VIEWSTATEGENERATOR", "D7823E0B")); postData.add(new BasicNameValuePair("__EVENTVALIDATION", eventValidation)); postData.add(new BasicNameValuePair("_ctl0:cphMain:SmartpassTextbox", getUsername())); postData.add(new BasicNameValuePair("_ctl0:cphMain:SubmitButton", "OK")); postData.add(new BasicNameValuePair("_ctl0:cphMain:chbRememberSmartPassCode", "on")); postData.add(new BasicNameValuePair("_ctl0:cphMain:cookieEnabled", "true")); return new LoginPackage(urlopen, postData, response, "https://www.dittkort.se//q/?p=7EB4F129-0A41-417F-8FEA-51B2B75B9D24"); }
From source file:org.wallride.web.support.Posts.java
public String thumbnail(Post post) { if (post.getCover() != null) { return wallRideProperties.getMediaUrlPrefix() + post.getCover().getId(); } else {/*from ww w . java 2 s .c o m*/ Document document = Jsoup.parse(post.getBody()); Elements elements = document.select("img"); for (Element element : elements) { return element.attr("src"); } } return null; }
From source file:com.liato.bankdroid.banking.banks.Nordnet.java
@Override protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException { urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_nordnet)); urlopen.setContentCharset(HTTP.ISO_8859_1); response = urlopen.open("https://www.nordnet.se/mux/login/startSE.html"); Document d = Jsoup.parse(response); Element e = d.getElementById("input1"); if (e == null || "".equals(e.attr("name"))) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " username field."); }//from ww w. j a va2 s.c om String loginFieldName = e.attr("name"); e = d.getElementById("pContHidden"); if (e == null || "".equals(e.attr("name"))) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " password field."); } String loginFieldPassword = e.attr("name"); List<NameValuePair> postData = new ArrayList<NameValuePair>(); postData.add(new BasicNameValuePair("checksum", "")); postData.add(new BasicNameValuePair("referer", "")); postData.add(new BasicNameValuePair("encryption", "0")); postData.add(new BasicNameValuePair(loginFieldName, username)); postData.add(new BasicNameValuePair(loginFieldPassword, password)); return new LoginPackage(urlopen, postData, response, "https://www.nordnet.se/mux/login/login.html"); }
From source file:com.example.muzei.muzeiapod.ApodNasaArtSource.java
@Override protected void onTryUpdate(int reason) throws RetryException { URI topUri;// www . j av a 2 s.c o m try { topUri = new URI("http://apod.nasa.gov/"); } catch (URISyntaxException e) { return; } URI mainUri = topUri.resolve("/apod/astropix.html"); String bodyStr = getURLContent(mainUri.toString()); /* TODO code below should go to a separate method/class */ /* start parsing page */ Document doc = Jsoup.parse(bodyStr); Element body = doc.body(); /* get image URI */ Element firstCenterTag = body.child(0); Element imgAnchor = firstCenterTag.getElementsByTag("a").last(); Element img = imgAnchor.getElementsByTag("img").first(); URI bigImageUri = topUri.resolve("/apod/" + img.attr("src")); String uri = bigImageUri.toString(); /* get title */ Element secondCenterTag = body.child(1); Element titleElem = secondCenterTag.child(0); String title = titleElem.text(); /* get byline */ String secondCenterText = secondCenterTag.text(); /* byline: everything after 'title' above */ int idx = secondCenterText.lastIndexOf(title) + title.length(); String byline = secondCenterText.substring(idx).trim(); /* TODO figure out the permanent link */ String link = "http://apod.nasa.gov/apod/astropix.html"; publishArtwork(new Artwork.Builder().title(title).byline(byline).imageUri(Uri.parse(uri)).token(title) .viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(link))).build()); scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS); }