Skip to content Skip to sidebar Skip to footer

How To Extract Text From A Webpage

First off, yes, I have done research on this question. And yes, I have found an answer here. But the whole process still isn't working for me. All I need to do is grab text off of

Solution 1:

@Ethan, sure, I hope this is what you want, just adding the readWebpage method in the onCreate method, but I modified it and removed the View object since it is not being used,

    public class Searching_Animation_Screen extends ActionBarActivity {
TextView loading_txt;
Animation blink;
public String pre_split;
public String[] split_string;
TextView text;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_searchinganimationscreen);
    ActionBar actionBar = getSupportActionBar();
    actionBar.hide();
    int width = getWindowManager().getDefaultDisplay().getWidth();
    loading_txt = (TextView)findViewById(R.id.loading);
    text =(TextView)findViewById(R.id.textView);
    Typeface pacifico_typeface = Typeface.createFromAsset(getAssets(), "fonts/pacifico.ttf");
   loading_txt.setTypeface(pacifico_typeface);
   loading_txt.setTextSize(width / 20);
   blink = AnimationUtils.loadAnimation(getApplicationContext(),
           R.anim.blink);
   loading_txt.setAnimation(blink);
   Begin();

  //* call webpage here, 
  //* note, i removed passing the view object since it is not being used
  readWebpage()

}

 //* (modify) by remvoving it from the code below 
 //* and removing the view object since it is not being used
 public void readWebpage() {
     DownloadWebPageTask task = new DownloadWebPageTask();
     task.execute(new String[] {"http://www.google.com"});

 }

private void Begin() {
    Intent SEARCH_INTENT = getIntent();
    pre_split=SEARCH_INTENT.getStringExtra("Search_Text");
    split_string = pre_split.split(" ");
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_searchinganimationscreen, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
    String google_url ="https://www.google.com/#safe=active&q=";

    @Override
    protected String doInBackground(String... urls) {
        String response = "";
        for (String url : urls) {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try {
                HttpResponse execute = client.execute(httpGet);
                InputStream content = execute.getEntity().getContent();

                BufferedReader buffer = new BufferedReader(
                        new InputStreamReader(content));
                String s = "";
                while ((s = buffer.readLine()) != null) {
                    response += s;
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return response;
    }

    @Override
    protected void onPostExecute(String result) {
        text.setText(Html.fromHtml(result));
        //throw into summarizer
    }

  }

}

Post a Comment for "How To Extract Text From A Webpage"