Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a search function on the site you're scraping that you can emulate using a HttpClient and a HttpPost, as shown in the following example.</p> <p>First and foremost, use a HttpClient - in this case AndroidHttpClient. We mimic the User-Agent of a real browser just in case:</p> <pre><code>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", this); </code></pre> <p>Then - an AsyncTask that will perform the network operation:</p> <pre><code>class GetPlayerTask extends AsyncTask&lt;String, Void, String&gt; { @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 onPlayerFound(result); } } </code></pre> <p>The <code>BasicNameValuePair</code>s above were scraped with 2-3s effort on their search page using FireBug. The response from a "successful search" is a redirect message (302), containing the location of the player page - i.e. the identifier you required to download the image.</p> <p>The <code>GetPlayerTask</code> would be used like this:</p> <pre><code> GetPlayerTask fetch = new GetPlayerTask(); // FirstName, LastName, Category (NBA/etc./etc.) fetch.execute("Gerald", "Henderson", "nba"); </code></pre> <p>This would return a path relative to www.rotoworld.com, e.g.</p> <pre><code>"/player/nba/1614/gerald-henderson" </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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