Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get a profile picture of an athlete from web page
    primarykey
    data
    text
    <p>I want to display the picture of the athlete depending on the selection of the player. I am using JSOUP in order to retrive the rest of the information like stats etc...I am havina a problem because the html keeps on changing by every player. I can feed the html the name but I dont know the id of evey player on selection. any ideas?</p> <p>HTNL example : <a href="http://www.rotoworld.com/player/nba/784/zach-randolph/1" rel="nofollow">http://www.rotoworld.com/player/nba/784/zach-randolph/1</a></p> <p>I can push the name when the player is selected (zach-randolph) but not his code(784)...</p> <p>Update-- Maybe I can do a google image search on the name and retrieve the first result anyone know how to do this?</p> <p>CODE:</p> <pre><code>public class ImagetestdroidActivity extends Activity { /** Called when the activity is first created. */ ImageView image = null; //ImageView image2 = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image = (ImageView)findViewById(R.id.imageView1); //image2 = (ImageView)findViewById(R.id.imageView2); GetPlayerTask fetch = new GetPlayerTask(); String phrase = "Lebron James"; String delims = "[ ]+"; String[] tokens = phrase.split(delims); for (int i = 0; i &lt; tokens.length; i++) { System.out.println("Token"+i+":"+tokens[i]); } fetch.execute(tokens[0], tokens[1], "nba"); } public String getimage(String html) throws IOException { try { Document doc = Jsoup.connect(html).get(); Element e = doc.select("div.playerphoto &gt; img").first(); // If you want absolute path String imgSrcAbs = e.attr("abs:src"); System.out.println(imgSrcAbs); // Or , If you want relative path String imgSrcRelative = e.attr("src"); System.out.println(imgSrcRelative); return imgSrcAbs; } catch (IOException e) { } return null; } public void onPlayerFound(String result) throws IOException { // TODO Auto-generated method stub System.out.println("in ONPLAYERFOUNFD"+result); String imagehtml= getimage("http://www.rotoworld.com/"+result+"/1"); try { System.out.println("IMG HTML "+imagehtml); URL feedImage = new URL(imagehtml); HttpURLConnection conn= (HttpURLConnection)feedImage.openConnection(); InputStream is = conn.getInputStream(); Bitmap img = BitmapFactory.decodeStream(is); image.setImageBitmap(img); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } class GetPlayerTask extends AsyncTask&lt;String, Void, String&gt; { private final String TAG = null; AndroidHttpClient mClient = AndroidHttpClient.newInstance( "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111107 Ubuntu/10.04 (lucid) Firefox/3.6.24"); @Override protected String doInBackground(String... params) { String result = null; String url = Uri.parse("http://www.rotoworld.com").buildUpon() .appendEncodedPath("content/playersearch.aspx") .appendQueryParameter("searchname", params[0] + " " + params[1]) .build().toString(); HttpPost post = new HttpPost(url); post.addHeader("Referer", "http://www.rotoworld.com"); try { List&lt;NameValuePair&gt; parameters = new ArrayList&lt;NameValuePair&gt;(); parameters.add(new BasicNameValuePair("ctl00$cp1$btnAdvancedSearch", "Search")); parameters.add(new BasicNameValuePair("ctl00$cp1$radSportSearch", params[2].toUpperCase())); parameters.add(new BasicNameValuePair("ctl00$cp1$tbFirstNameSearch", params[0])); parameters.add(new BasicNameValuePair("ctl00$cp1$tbLastNameSearch", params[1])); parameters.add(new BasicNameValuePair("ctl00$cp1$tbHeaderSearchBox", "LAST NAME, FIRST NAME")); parameters.add(new BasicNameValuePair("ctl00$cp1$headlinesNFL$hideHeadlineSport", "")); parameters.add(new BasicNameValuePair("ctl00$cp1$siteheader$hidpage", "")); parameters.add(new BasicNameValuePair("__EVENTARGUMENT", "")); parameters.add(new BasicNameValuePair("__EVENTTARGET", "")); parameters.add(new BasicNameValuePair("__EVENTVALIDATION", "/wEWEALJp4KIBAKHlvL3BgLA+sClCQK5vLryBgKn1MPhBAK9kM36BQKj89HmAwLA+vrmBAKk7ayNDgKj85nnAwKU87XnAwKurM6nDAK++qLmBAKD2r2iBgKQ+47mAgK//t/aB6qbH1ovSUf6LkMO7LTmIW5EbRu5")); parameters.add(new BasicNameValuePair("__VIEWSTATE", "/wEPDwUJMjg1NjcxOTA2D2QWAmYPZBYEAgEPZBYCAhwPFgIeBFRleHQF3AE8c2NyaXB0IGxhbmd1YWdlPSdqYXZhc2NyaXB0JyB0eXBlPSd0ZXh0L2phdmFzY3JpcHQnIHNyYz0naHR0cDovL2FqYXguZ29vZ2xlYXBpcy5jb20vYWpheC9saWJzL2pxdWVyeS8xLjQuMi9qcXVlcnkubWluLmpzJz48L3NjcmlwdD48c2NyaXB0IGxhbmd1YWdlPSdqYXZhc2NyaXB0JyB0eXBlPSd0ZXh0L2phdmFzY3JpcHQnIHNyYz0nL3psaWJzL2ZseW91dG5hdi5qcyc+PC9zY3JpcHQ+ZAIDD2QWAgIBD2QWAgIDD2QWBAIFD2QWBgIBDxYCHwAFDVRvcCBIZWFkbGluZXNkAgIPDxYCHgdWaXNpYmxlaGRkAgQPD2QPEBYBZhYBFgIeDlBhcmFtZXRlclZhbHVlZRYBZmRkAgsPZBYCAgEPFgIfAAUbQ2hhbXBpb25zaGlwIEV2ZW50cyBUaWNrZXRzZGRb2hpHPON4Q4VOuUHYhpgRZg0o4Q==")); post.setEntity(new UrlEncodedFormEntity(parameters)); HttpResponse response = mClient.execute(post); if (response.getStatusLine().getStatusCode() == 302) { Header location = response.getFirstHeader("Location"); if (location != null) { result = location.getValue(); } } } catch (IOException e) { Log.e(TAG, "Unable perform request", e); } return result; } @Override protected void onPostExecute(String result) { // Call whatever method you want to notify your Activity // that you've found the player in question try { System.out.println("getplayer"+result); onPlayerFound(result); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload