Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:16:04+00:00 2026-06-11T13:16:04+00:00

I need to extract web page source to string in Android. I tried to

  • 0

I need to extract web page source to string in Android. I tried to do it using HttpClient, HttpGet and HttpResponse, but this method doesn’t work. I have to do try/catch to every initialization of this methods and anyway, the application force closes.

  public static String getHtmlSource(String webPage){
            HttpClient client = new DefaultHttpClient();
            URI url = null;
            try {
                url = new URI("http://www.kinopoisk.ru/film/581493");
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            HttpGet request = new HttpGet(url);
            HttpResponse response = null;
            try {
                response = client.execute(request);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            String html = "";
            InputStream in = null;
            try {
                in = response.getEntity().getContent();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            StringBuilder str = new StringBuilder();
            String line = null;
            try {
                while((line = reader.readLine()) != null)
                {
                    str.append(line);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                in.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            html = str.toString();
            return html;
        }

LogCat

09-18 19:28:07.989: W/dalvikvm(5708): threadid=1: thread exiting with uncaught exception (group=0x41f64300)
09-18 19:28:08.029: E/AndroidRuntime(5708): FATAL EXCEPTION: main
09-18 19:28:08.029: E/AndroidRuntime(5708): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gavrilov.egor.movies/com.gavrilov.egor.movies.MoviesList}: android.os.NetworkOnMainThreadException
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.os.Looper.loop(Looper.java:137)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.app.ActivityThread.main(ActivityThread.java:4745)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at java.lang.reflect.Method.invokeNative(Native Method)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at java.lang.reflect.Method.invoke(Method.java:511)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at dalvik.system.NativeStart.main(Native Method)
09-18 19:28:08.029: E/AndroidRuntime(5708): Caused by: android.os.NetworkOnMainThreadException
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at com.gavrilov.egor.movies.ParseHtmlPage.getHtmlSource(ParseHtmlPage.java:32)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at com.gavrilov.egor.movies.MoviesList.onCreate(MoviesList.java:30)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.app.Activity.performCreate(Activity.java:5008)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-18 19:28:08.029: E/AndroidRuntime(5708):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:16:05+00:00Added an answer on June 11, 2026 at 1:16 pm

    Can it be you don’t have INTERNET permission in the manifest?

    Edit: Ah, you are doing that on the main thread, no?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract information from an unstructured web page in Android. The information
I need to extract the meta keywords from a web page using Python. I
I need to extract text from any kind of web page using regex in
I have a source to a web page and I need to extract the
I need to extract pure text form a random web page at runtime, on
I need to extract the text (only plain text) from an arbitrary web page
I am working on a program and need to extract TLD and web page
I want to split this string up into parts like Source: Web, Pics: 1
I need to take a web page and extract the address information from the
I need to extract this text: Line 1 text. Line 2 text. Line 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.