Hi Mark Murphy,
will you please help me in reading html source code
please its important for me for this url
I have edited my code in the following way
but i am getting same problem
will you please check it once
my code is as follows
public class InstagramAlbumsActivity extends Activity {
String url = "http://ncpo.cc/test/example.php";
Button login;
org.apache.http.HttpResponse response;
WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.openingwebpage);
mWebView = (WebView) findViewById(R.id.webView1);
Log.d("Calc", "gghfhfhf");
mWebView.setWebViewClient(new HelloWebViewClient());
Log.d("Calc", "gghfhfhf ghgfhhg");
mWebView.getSettings().setJavaScriptEnabled(true);
Log.d("Calc", "gghfhfhfghjghjgjhggkhljjk;kl''");
mWebView.clearCache(true);
mWebView.setWebChromeClient(new WebChromeClient());
Log.d("Calc", "gghfhfhf swathi 1");
mWebView.addJavascriptInterface(new HtmlHandler(), "HTMLOUT");
mWebView.loadUrl(url);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
mWebView.loadUrl("javascript:window.HTMLOUT.processHTML('<div>'+document.getElementsByTagName('html')[0].innerHTML+'</div>');");
}
}
final class HtmlHandler {
public void processHTML(String html) {
// process the html as needed by the app
Log.d("dgdffghgh", "swathi in hyderabad");
Get_Webpage obj = new Get_Webpage(url);
Log.d("swathi", "gghfhfhf swathi
loading");
String source = obj.get_webpage_source();
Log.d("html loading", source);
}
}
public class Get_Webpage {
public String parsing_url = "";
public Get_Webpage(String url_2_get) {
parsing_url = url_2_get;
}
public String get_webpage_source() {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(parsing_url);
HttpResponse response = null;
try {
response = client.execute(request);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
String html = "";
InputStream in = null;
try {
in = response.getEntity().getContent();
} catch (IllegalStateException e) {
} catch (IOException e) {
}
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) {
}
try {
in.close();
} catch (IOException e) {
}
html = str.toString();
return html;
}
}
}
On Thu, Mar 15, 2012 at 4:15 PM, Mark Murphy <[email protected]>wrote:
> 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 <[email protected]>
> 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 [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en