List of usage examples for org.jsoup.nodes Element attr
public String attr(String attributeKey)
From source file:ca.zadrox.dota2esportticker.service.UpdateTeamsService.java
private void updateSearchedTeams(String searchName) { LOGD(TAG, "starting search update"); // actually, first, check for connectivity: if (!checkForConnectivity()) { LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(STATUS_NO_CONNECTIVITY)); LOGD(TAG, "returning due to no connectivity"); return;/*w w w . ja va2s . c om*/ } LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(STATUS_UPDATING)); final String BASE_URL = "http://www.gosugamers.net/dota2/rankings" + "?tname=" + searchName.replace(' ', '+') + "&tunranked=0#team"; final String TEAM_LINK_BASE_URL = "http://www.gosugamers.net/dota2/teams/"; try { String rawHtml = new OkHttpClient().newCall(new Request.Builder().url(BASE_URL).build()).execute() .body().string(); String processedHtml = rawHtml.substring(rawHtml.indexOf("<div id=\"col1\" class=\"rows\">"), rawHtml.indexOf("<div id=\"col2\" class=\"rows\">")); Elements teamRows = Jsoup.parse(processedHtml).getElementsByClass("ranking-link"); ExecutorService executorService = Executors.newFixedThreadPool(10); HashMap<ContentValues, Future<String>> newTeamInfo = new HashMap<ContentValues, Future<String>>(); HashMap<ContentValues, Future<String>> updateTeamInfo = new HashMap<ContentValues, Future<String>>(); for (Element teamRow : teamRows) { ContentValues contentValues = new ContentValues(); String teamId = teamRow.attr("data-id"); contentValues.put(MatchContract.TeamEntry._ID, teamId); String untrimmedTeamName = teamRow.getElementsByTag("h4").first().text(); String teamUrl = TEAM_LINK_BASE_URL + teamId + "-" + untrimmedTeamName.replaceAll("[\\W]?[\\W][\\W]*", "-").toLowerCase(); contentValues.put(MatchContract.TeamEntry.COLUMN_TEAM_URL, teamUrl); String teamName = untrimmedTeamName.replaceAll(" ?\\.?\\-?-?Dot[aA][\\s]?2", ""); contentValues.put(MatchContract.TeamEntry.COLUMN_TEAM_NAME, teamName); if (teamUrl.charAt(teamUrl.length() - 1) == '-') { teamUrl = teamUrl.substring(0, teamUrl.length() - 2); } // then, we query db for id of the team ( Cursor cursor = getContentResolver().query( MatchContract.TeamEntry.buildTeamUri(Long.parseLong(teamId)), new String[] { MatchContract.TeamEntry.COLUMN_TEAM_NAME, MatchContract.TeamEntry.COLUMN_TEAM_URL }, null, null, null); // -> if present, and data remains unchanged, continue. // -> if present, but data is changed, add to update queue. if (cursor.moveToFirst()) { LOGD(TAG, "Team in DB, determining if values need updating"); if (!cursor.getString(0).contentEquals(teamName) || !cursor.getString(1).contentEquals(teamUrl)) { LOGD(TAG, "Team has updated values, double checking logo & writing to DB"); updateTeamInfo.put(contentValues, executorService.submit(new TeamGetter(teamUrl))); } } // -> if not present, add to update queue. else { LOGD(TAG, "Team not in DB. Grabbing logo & writing to DB"); newTeamInfo.put(contentValues, executorService.submit(new TeamGetter(teamUrl))); } // LOGD(TAG, "\n" + // "data-id: " + teamId + "\n" + // "team-name: " + teamName + "\n" + // "team-url: " + teamUrl); // cursor.close(); } executorService.shutdown(); executorService.awaitTermination(20, TimeUnit.SECONDS); for (ContentValues contentValues : newTeamInfo.keySet()) { try { String teamLogo = newTeamInfo.get(contentValues).get(); contentValues.put(MatchContract.TeamEntry.COLUMN_TEAM_LOGO_URL, teamLogo); } catch (ExecutionException e) { LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(STATUS_ERROR)); e.printStackTrace(); } } for (ContentValues contentValues : updateTeamInfo.keySet()) { try { String teamLogo = newTeamInfo.get(contentValues).get(); contentValues.put(MatchContract.TeamEntry.COLUMN_TEAM_LOGO_URL, teamLogo); String teamId = contentValues.getAsString(MatchContract.TeamEntry._ID); contentValues.remove(MatchContract.TeamEntry._ID); int updatedRows = getContentResolver().update(MatchContract.TeamEntry.CONTENT_URI, contentValues, MatchContract.TeamEntry.TABLE_NAME + "." + MatchContract.TeamEntry._ID + " = ?", new String[] { teamId }); LOGD(TAG, "updatedRows: " + updatedRows); } catch (ExecutionException e) { LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(STATUS_ERROR)); e.printStackTrace(); } } getContentResolver().bulkInsert(MatchContract.TeamEntry.CONTENT_URI, newTeamInfo.keySet().toArray(new ContentValues[newTeamInfo.size()])); } catch (IOException e) { LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(STATUS_ERROR)); e.printStackTrace(); } catch (InterruptedException e2) { LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(STATUS_ERROR)); e2.printStackTrace(); } // String[] projection = new String[]{ // MatchContract.TeamEntry.TABLE_NAME + "." + MatchContract.TeamEntry._ID, // MatchContract.TeamEntry.COLUMN_TEAM_NAME, // MatchContract.TeamEntry.COLUMN_TEAM_URL, // MatchContract.TeamEntry.COLUMN_TEAM_LOGO_URL, // MatchContract.TeamEntry.COLUMN_TEAM_STARRED, // }; // // String sortOrder = // MatchContract.TeamEntry.COLUMN_TEAM_NAME + " ASC"; // // Cursor c = getContentResolver().query( // MatchContract.TeamEntry.CONTENT_URI, // projection, // MatchContract.TeamEntry.COLUMN_TEAM_NAME + " LIKE '%" + searchName + "%'", // null, // sortOrder // ); // // LOGD(TAG+"/UST", "Starting Printout: "); // int i = 0; // while (c.moveToNext()) { // String teamPrintOut = // "teamId: " + c.getInt(0) + " teamName: " + c.getString(1) + "\n" + // "teamUrl: " + c.getString(2) + "\n" + // "teamLogoUrl: " + c.getString(3) + "\n" + // "isFavourited: " + (c.getInt(4) == 0 ? "false" : "true"); // LOGD(TAG + "/UST", teamPrintOut); // i++; // } // LOGD(TAG+"/UST", "Stopping Printout. Count: " + i); // // c.close(); // use local broadcast manager to hide loading indicator // and signal that cursorloader for top50 can happen. LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(STATUS_COMPLETED)); }
From source file:cc.metapro.openct.custom.CustomPresenter.java
@Override public void setWebView(final InteractiveWebView webView, final FragmentManager manager) { webView.setUserClickCallback(new InteractiveWebView.ClickCallback() { @Override/*from ww w. j a va 2 s . c om*/ public void onClick(@NonNull final Element element) { if (HTMLUtils.isPasswordInput(element)) { if (!webView.setById(element.id(), "value", mPassword)) { webView.setByName(element.attr("name"), "value", mPassword); } } else if (HTMLUtils.isTextInput(element)) { ClickDialog.newInstance(new ClickDialog.TypeCallback() { @Override public void onResult(String type) { switch (type) { case InteractiveWebView.COMMON_INPUT_FLAG: if (!webView.focusById(element.id())) { webView.focusByName(element.attr("name")); } break; case InteractiveWebView.USERNAME_INPUT_FLAG: if (!webView.setById(element.id(), "value", mUsername)) { webView.setByName(element.attr("name"), "value", mUsername); } break; } } }).show(manager, "click_dialog"); } } }); }
From source file:com.example.android.animationsdemo.FacebookSdkActivity.java
public void testCurl() { new Thread() { public void run() { String url = "https://fb.me/410173292515376 "; Log.i(TAG, "Requesting URL to download: " + url); byte[] result = downloadUrl(url); String contentString = result == null ? "Null" : new String(result); Log.i(TAG, contentString);//w w w .ja v a 2s . c o m Document doc = Jsoup.parse(contentString); Elements elements = doc.select("META"); for (Element element : elements) { String prop = element.attr("property"); if (prop.equals("al:android:url")) { String content = element.attr("content"); DKLog.d(TAG, Trace.getCurrentMethod() + content); if (content.contains("fbSwapub") && content.contains("ProductID")) { String productID = content.substring(content.lastIndexOf("/") + 1); DKLog.d(TAG, Trace.getCurrentMethod() + productID); } } } } }.start(); }
From source file:com.example.android.animationsdemo.ImageSearchActivity.java
/** * * @param question image search term// w w w.j a v a2 s . c o m * @param ua user agent of the browser * @return */ private String findImage(String question, String ua) { String finRes = ""; try { String googleUrl = "https://www.google.com/search?tbm=isch&q=" + question.replace(",", ""); Document doc1 = Jsoup.connect(googleUrl).userAgent(ua).timeout(10 * 1000).get(); DKLog.d(TAG, Trace.getCurrentMethod() + doc1); Element media = doc1.select("[data-src]").first(); String finUrl = media.attr("abs:data-src"); finRes = "<a href=\"http://images.google.com/search?tbm=isch&q=" + question + "\"><img src=\"" + finUrl.replace(""", "") + "\" border=1/></a>"; DKLog.d(TAG, Trace.getCurrentMethod() + finRes); } catch (Exception e) { DKLog.e(TAG, Trace.getCurrentMethod() + e.toString()); } return finRes; }
From source file:com.licubeclub.zionhs.MainActivity.java
void networkTask() { SRL.setRefreshing(true);/*from w ww .j a v a2s . co m*/ final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { } }; final Handler mHandler = new Handler(); new Thread() { public void run() { mHandler.post(new Runnable() { public void run() { // SRL.setRefreshing(true); } }); try { lunchstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "2"); //Get Lunch Menu Date dinnerstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "3"); //Get Dinner Menu Date } catch (Exception e) { } try { int skipcount = 0; boolean skipped = false; schedulearray = new ArrayList<String>(); dayarray = new ArrayList<String>(); // ? ?? ? ?? Document doc = Jsoup.connect(URL).get(); Elements rawdaydata = doc.select(".listDay"); //Get contents from the class,"listDay" for (Element el : rawdaydata) { String daydata = el.text(); if (daydata.equals("") | daydata == null) { if (skipped) { } else { skipcount++; } } else { dayarray.add(daydata); // add value to ArrayList skipped = true; } } Log.d("Schedule", "Parsed Day Array" + dayarray); Elements rawscheduledata = doc.select(".listData"); //Get contents from tags,"a" which are in the class,"ellipsis" for (Element el : rawscheduledata) { String scheduledata = el.text(); if (skipcount > 0) { skipcount--; } else { schedulearray.add(scheduledata); // add value to ArrayList } } Log.d("Schedule", "Parsed Schedule Array" + schedulearray); // SRL.setRefreshing(false); } catch (IOException e) { e.printStackTrace(); // SRL.setRefreshing(false); } try { titlearray_np = new ArrayList<String>(); Document doc = Jsoup.connect( "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59") .get(); Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody" String titlestring = rawdata.toString(); Log.i("Notices", "Parsed Strings" + titlestring); for (Element el : rawdata) { String titledata = el.attr("title"); titlearray_np.add(titledata); // add value to ArrayList } Log.i("Notices", "Parsed Array Strings" + titlearray_np); } catch (IOException e) { e.printStackTrace(); } //Notices URL try { titlearray_n = new ArrayList<String>(); // ? URL Document doc = Jsoup.connect( "http://www.zion.hs.kr/main.php?" + "menugrp=110100&master=bbs&act=list&master_sid=58") .get(); //Get contents from tags,"a" which are in the class,"listbody" Elements rawmaindata = doc.select(".listbody a"); String titlestring = rawmaindata.toString(); Log.i("Notices", "Parsed Strings" + titlestring); // ?? ? for (Element el : rawmaindata) { String titledata = el.attr("title"); titlearray_n.add(titledata); // add value to ArrayList } Log.i("Notices", "Parsed Array Strings" + titlearray_n); } catch (IOException e) { e.printStackTrace(); } mHandler.post(new Runnable() { public void run() { // progressDialog.dismiss(); // SRL.setRefreshing(false); if (AMorPM == Calendar.AM) { MealString = lunchstring[DAYofWEEK - 1]; } else { MealString = dinnerstring[DAYofWEEK - 1]; } try { ScheduleString = schedulearray.get(DAYofMONTH - 1); NoticesParentString = titlearray_np.get(0); NoticeString = titlearray_n.get(0); } catch (Exception e) { ScheduleString = getResources().getString(R.string.error); NoticesParentString = getResources().getString(R.string.error); NoticeString = getResources().getString(R.string.error); } if (MealString == null) { MealString = getResources().getString(R.string.nodata); } else if (MealString.equals("")) { MealString = getResources().getString(R.string.nodata); } if (ScheduleString == null) { ScheduleString = getResources().getString(R.string.nodata); } else if (ScheduleString.equals("")) { ScheduleString = getResources().getString(R.string.nodata); } SRL.setRefreshing(false); handler.sendEmptyMessage(0); setContentData(); } }); } }.start(); }
From source file:com.licubeclub.zionhs.Notices.java
private void networkTask() { NetworkChecker NetCheck = new NetworkChecker(Notices.this); if (NetCheck.isNetworkConnected()) { final Handler mHandler = new Handler(); new Thread() { public void run() { mHandler.post(new Runnable() { public void run() { SRL.setRefreshing(true); }// w w w.java 2 s. co m }); //Task //Notices URL try { titlearray = new ArrayList<String>(); titleherfarray = new ArrayList<String>(); authorarray = new ArrayList<String>(); datearray = new ArrayList<String>(); // ? URL Document doc = Jsoup.connect(url).get(); Elements rawmaindata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody" Elements rawauthordata = doc.select("td:eq(3)"); //? ? - 3 td ? Elements rawdatedata = doc.select("td:eq(4)"); // ? - 4 td ? String titlestring = rawmaindata.toString(); Log.i("Notices", "Parsed Strings" + titlestring); // ?? ? for (Element el : rawmaindata) { String titlherfedata = el.attr("href"); String titledata = el.attr("title"); titleherfarray.add("http://www.zion.hs.kr/" + titlherfedata); // add value to ArrayList titlearray.add(titledata); // add value to ArrayList } Log.i("Notices", "Parsed Link Array Strings" + titleherfarray); Log.i("Notices", "Parsed Array Strings" + titlearray); for (Element el : rawauthordata) { String authordata = el.text(); Log.d("Author", el.text()); authorarray.add(authordata); } for (Element el : rawdatedata) { String datedata = el.text(); Log.d("Date", el.text()); datearray.add(datedata); } } catch (IOException e) { e.printStackTrace(); } mHandler.post(new Runnable() { public void run() { //UI Task // ? adapter = new PostListAdapter(Notices.this, titlearray, datearray, authorarray); listview.setAdapter(adapter); listview.setOnItemClickListener(GoToWebPage); handler.sendEmptyMessage(0); SRL.setRefreshing(false); Toast.makeText(getApplicationContext(), getResources().getString(R.string.recent), Toast.LENGTH_LONG).show(); } }); } }.start(); } else { Toast.makeText(getApplicationContext(), getString(R.string.network_connection_warning), Toast.LENGTH_LONG).show(); } }
From source file:com.licubeclub.zionhs.Notices_Parents.java
private void networkTask() { final Handler mHandler = new Handler(); new Thread() { public void run() { mHandler.post(new Runnable() { public void run() { SRL.setRefreshing(true); }// w ww .j a va2 s . c o m }); //Task //Notices URL try { titlearray = new ArrayList<String>(); titleherfarray = new ArrayList<String>(); authorarray = new ArrayList<String>(); datearray = new ArrayList<String>(); Document doc = Jsoup.connect( "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59") .get(); Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody" Elements rawauthordata = doc.select("td:eq(3)"); //? ? - 3 td ? Elements rawdatedata = doc.select("td:eq(4)"); // ? - 4 td ? String titlestring = rawdata.toString(); Log.i("Notices", "Parsed Strings" + titlestring); for (Element el : rawdata) { String titlherfedata = el.attr("href"); String titledata = el.attr("title"); titleherfarray.add("http://www.zion.hs.kr/" + titlherfedata); // add value to ArrayList titlearray.add(titledata); // add value to ArrayList } Log.i("Notices", "Parsed Link Array Strings" + titleherfarray); Log.i("Notices", "Parsed Array Strings" + titlearray); for (Element el : rawauthordata) { String authordata = el.text(); Log.d("Author", el.text()); authorarray.add(authordata); } for (Element el : rawdatedata) { String datedata = el.text(); Log.d("Date", el.text()); datearray.add(datedata); } } catch (IOException e) { e.printStackTrace(); } mHandler.post(new Runnable() { public void run() { //UI Task adapter = new PostListAdapter(Notices_Parents.this, titlearray, datearray, authorarray); listview.setAdapter(adapter); listview.setOnItemClickListener(GoToWebPage); handler.sendEmptyMessage(0); SRL.setRefreshing(false); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.noti_parents_info), Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); } }); } }.start(); }
From source file:com.lloydtorres.stately.explore.ExploreActivity.java
/** * Gets the required local ID for a target page. * @param url Target page URL//from w ww . j a v a 2s .com * @param password Password for region moves (can be null) */ private void getLocalId(final String url, final String password) { if (isInProgress) { SparkleHelper.makeSnackbar(view, getString(R.string.multiple_request_error)); return; } isInProgress = true; NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String response) { Document d = Jsoup.parse(response, SparkleHelper.BASE_URI); Element input = d.select("input[name=localid]").first(); if (input == null) { SparkleHelper.makeSnackbar(view, getString(R.string.login_error_parsing)); isInProgress = false; return; } String localid = input.attr("value"); switch (mode) { case EXPLORE_NATION: postEndorsement(localid); break; case EXPLORE_REGION: postRegionMove(localid, password); break; } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { SparkleHelper.logError(error.toString()); isInProgress = false; if (error instanceof TimeoutError || error instanceof NoConnectionError || error instanceof NetworkError) { SparkleHelper.makeSnackbar(view, getString(R.string.login_error_no_internet)); } else { SparkleHelper.makeSnackbar(view, getString(R.string.login_error_generic)); } } }); if (!DashHelper.getInstance(this).addRequest(stringRequest)) { isInProgress = false; SparkleHelper.makeSnackbar(view, getString(R.string.rate_limit_error)); } }
From source file:com.lloydtorres.stately.issues.IssueDecisionActivity.java
/** * Process the received page into the Issue and its IssueOptions * @param v Activity view/*w w w .ja v a 2s . c om*/ * @param d Document received from NationStates */ private void processIssueInfo(View v, Document d) { // First check if the issue is still available if (d.text().contains(NOT_AVAILABLE)) { mSwipeRefreshLayout.setRefreshing(false); SparkleHelper.makeSnackbar(v, String.format(Locale.US, getString(R.string.issue_unavailable), mNation.name)); return; } Element issueInfoContainer = d.select("div#dilemma").first(); if (issueInfoContainer == null) { // safety check mSwipeRefreshLayout.setRefreshing(false); SparkleHelper.makeSnackbar(v, getString(R.string.login_error_parsing)); return; } Elements issueInfoRaw = issueInfoContainer.children(); String issueText = issueInfoRaw.select("p").first().text(); // If this is an issue chain, grab the second paragraph instead if (d.select("div.dilemmachain").first() != null) { issueText = issueInfoRaw.select("p").get(1).text(); if (d.text().contains(STORY_SO_FAR)) { issueText = issueText + "<br><br>" + issueInfoRaw.select("p").get(2).text(); } } issue.content = issueText; issue.options = new ArrayList<IssueOption>(); Element optionHolderMain = issueInfoRaw.select("ol.diloptions").first(); if (optionHolderMain != null) { Elements optionsHolder = optionHolderMain.select("li"); int i = 0; for (Element option : optionsHolder) { IssueOption issueOption = new IssueOption(); issueOption.index = i++; Element button = option.select("button").first(); if (button != null) { issueOption.header = button.attr("name"); } else { issueOption.header = IssueOption.SELECTED_HEADER; } Element optionContentHolder = option.select("p").first(); if (optionContentHolder == null) { // safety check mSwipeRefreshLayout.setRefreshing(false); SparkleHelper.makeSnackbar(v, getString(R.string.login_error_parsing)); return; } issueOption.content = optionContentHolder.text(); issue.options.add(issueOption); } } IssueOption dismissOption = new IssueOption(); dismissOption.index = -1; dismissOption.header = IssueOption.DISMISS_HEADER; dismissOption.content = ""; issue.options.add(dismissOption); setRecyclerAdapter(issue); mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setEnabled(false); }
From source file:com.lloydtorres.stately.issues.IssuesFragment.java
/** * Process the HTML contents of the issues into actual Issue objects * @param d/*from w ww . jav a 2s . com*/ */ private void processIssues(View v, Document d) { issues = new ArrayList<Object>(); Element issuesContainer = d.select("ul.dilemmalist").first(); if (issuesContainer == null) { // safety check mSwipeRefreshLayout.setRefreshing(false); SparkleHelper.makeSnackbar(v, getString(R.string.login_error_parsing)); return; } Elements issuesRaw = issuesContainer.children(); for (Element i : issuesRaw) { Issue issueCore = new Issue(); Elements issueContents = i.children(); // Get issue ID and name Element issueMain = issueContents.select("a").first(); if (issueMain == null) { continue; } String issueLink = issueMain.attr("href"); issueCore.id = Integer.valueOf(issueLink.replace("page=show_dilemma/dilemma=", "")); Matcher chainMatcher = CHAIN_ISSUE_REGEX.matcher(issueMain.text()); if (chainMatcher.find()) { issueCore.chain = chainMatcher.group(1); issueCore.title = chainMatcher.group(2); } else { issueCore.title = issueMain.text(); } issues.add(issueCore); } Element nextIssueUpdate = d.select("p.dilemmanextupdate").first(); if (nextIssueUpdate != null) { String nextUpdate = nextIssueUpdate.text(); issues.add(nextUpdate); } if (issuesRaw.size() <= 0) { String nextUpdate = getString(R.string.no_issues); Matcher m = NEXT_ISSUE_REGEX.matcher(d.html()); if (m.find()) { long nextUpdateTime = Long.valueOf(m.group(1)) / 1000L; nextUpdate = String.format(Locale.US, getString(R.string.next_issue), SparkleHelper.getReadableDateFromUTC(getContext(), nextUpdateTime)); } issues.add(nextUpdate); } if (mRecyclerAdapter == null) { mRecyclerAdapter = new IssuesRecyclerAdapter(getContext(), issues, mNation); mRecyclerView.setAdapter(mRecyclerAdapter); } else { ((IssuesRecyclerAdapter) mRecyclerAdapter).setIssueCards(issues); } mSwipeRefreshLayout.setRefreshing(false); }