Thursday, March 15, 2012

Re: [android-developers] Need help on reading the html source of a page

You are not "reading html source code of a page after page loading".
You are downloading *a second copy of the page*.

There is no direct means of getting at the HTML presently displayed in
a WebView. Here is a StackOverflow question with some answers
demonstrating some workarounds:

http://stackoverflow.com/questions/2376471/how-do-i-get-the-web-page-contents-from-a-webview

On Thu, Mar 15, 2012 at 1:12 AM, chowdary nani <naveenneelinfo@gmail.com> wrote:
> Hi All
> I need help on reading html source code of a page after page loading in
> android
> following is my code
> Here i am able
> to read the source but the access tokens,user id and some data of the page
> are missing
> please help me.
>
>
>
> public void onPageFinished(WebView view, String url) {
>             // TODO Auto-generated method stub
>             super.onPageFinished(view, url);
>             try {
>                 URL urlObj = new URL("http://ncpo.cc/test/example.php");
>                 Log.d("url", urlObj.getHost());
>                 HttpClient client = new DefaultHttpClient();
>                 HttpGet request = new HttpGet(url);
>
>                 response = client.execute(request);
>
>                 String html = "";
>                 java.io.InputStream in = response.getEntity().getContent();
>                 BufferedReader reader = new BufferedReader(
>                         new InputStreamReader(in));
>                 StringBuilder str = new StringBuilder();
>                 String line = null;
>                 while ((line = reader.readLine()) != null) {
>                     str.append(line);
>                 }
>                 while ((line = reader.readLine()) != null) {
>                     str.append(line);
>                 }
>
>                 in.close();
>                 html = str.toString();
>                 if (html.contains("): <!DOCTYPE html PUBLIC ")) {
>
>                 } else {
>
>                     if (html.contains("Popular Media")) {
>                         mWebView.loadUrl(url);
>
>                     } else {
>                         Log.d("html in the else begining", html);
>
>                                             }
>                 }
>
>             } catch (ClientProtocolException e) {
>                 // TODO Auto-generated catch block
>                 e.printStackTrace();
>             } catch (IOException e) {
>                 // TODO Auto-generated catch block
>                 e.printStackTrace();
>             }
>         }
>     }
>
>
>
>
> Please help me to solve this problem.
>
>
> Thanks
> Naveen.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment