I'm trying to load the parsed html data from an rss feed using a
WebView, but the webview claims that the page:
"data:text/html;utf-8,[The html I'm trying to display]"
is not available.
I find it strange that it seems to be putting the html data into the
url, when I just want it to display it.
Here's my code right now for the webview:
Bundle data = getIntent().getExtras();
WebView webview = new WebView(this);
setContentView(webview);
webview.loadData(data.getString("DEFAULTTEXT"), "text/html", "utf-8");
Where the HTML has been passed in a string in the Bundle with the
identifier: DEFAULTTEXT. I've tested the class and the HTML is passed
fine, it just isn't displayed correctly.
It works fine on some of the webpages I've tried, but not others. I'll try to post the code of one that works and one that doesn't.
Huuu.... so I turned my computer on this morning and it worked perfectly. I still don't know what the problem was. :/
Edit: Never mind. It works on some, but not all of the pages I try to display.
Edit2: swapping it out for loadDataWithBaseURL worked like a charm.
As stated, when you have characters like '%', '\', '#' in your HTML, it needs to be escaped which loadData doesn't seem to do automatically.
loadDataWithBaseURL instead of loadData does escape and seems to fix this. Just use null for baseUrl and historyUrl. So the example code in the question is changed to:
Bundle data = getIntent().getExtras();
WebView webview = new WebView(this);
setContentView(webview);
webview.loadDataWithBaseURL(null,data.getString("DEFAULTTEXT"), "text/html", "utf-8",null);
I believe this sporadic behavior of loadData* is because of what is the content of the page you are trying to load. If it is plain simple html it has no problem. But if it has components like css or other features requiring external info, it will bail out.
My experience!
Are you sure you have the correct permissions defined in the manifest.xml?
Related
I am stuck at an issue, I don't know if its possible or not.
I need to call a HTML page, but the page has some content being loaded via Javascript too and I need to get that also.
Is this some how possible ?
Currently I have used plain: new URL(url).openConnection() and it's not returning that.
Any Help ?
Thanks
To do that you'll need to host a WebView in your application. It can be hidden if you want. Call the webview loadUrl to load the content you want. Handle the WebViewClient onPageFinished so you know all of the content has loaded, and then use the javascript bridge interface (addJavascriptInterface) to pass the HTML back up to the application.
I've created an application which lists all the feed items in ListFragment. My question is how to load the full text from the link. I've tried with WebView, but it is loading the complete URL. Since RSS XML structure does not have any tags related to full/actual content, can anyone give some reference so that I can use it?
This is how I've tried to load the URL in WebView:
URL = getIntent().getStringExtra("url");
webView = (WebView) findViewById(R.id.activity_display_news_webview);
webView.loadUrl(URL);
You can use boilerpipe to extract the full text from the url
i have an application that fetch html from a websites, exactly in a webpage permitted only tu logged in user, so i have setted the login cookie and i get back the html webpage to a string, i tryied to easily take this string off from emulator, but i can't do copy-paste trought emulator-pc, does someone know how can i load a webview to reder my string and make me seeing if i am logged in and all work or not?
If it's possible i'd like to directly render the string, without saving it to an html file and opening it... is this possible?
Thanks, matteo.
Setting webview content form String:
public static void loadHtmlToWebView(WebView view, String html) {
view.loadData(Base64.encodeToString(html.getBytes(), Base64.DEFAULT) , "text/html", "base64");
}
I'm trying to get some values from a site but these values only appears when I use a Browser, like Mozilla. When I use the Jsoup I can get the HTML from the site but without values, only with the tags.
This is the site I'm trying to parse:
http://www.submarinoviagens.com.br/Passagens/selecionarvoo?Origem=nat&Destino=mia&Data=05/11/2012&Hora=&Origem=mia&Destino=nat&Data=09/11/2012&Hora=&NumADT=1&NumCHD=0&NumINF=0&SomenteDireto=0&Cia=&SelCabin=&utm_source=&utm_medium=&utm_campaign=&CPId=
I'm trying to get the values that appears inside these span tags:
If I access the previous URL from a web browser I can see the following values: '', 'R$ 2634,22' and 'R$ 2634,22', but when I use the following code the values disapears.
URL url = new URL("http://www.submarinoviagens.com.br/Passagens/selecionarvoo?Origem=nat&Destino=mia&Data=05/11/2012&Hora=&Origem=mia&Destino=nat"+
"&Data=09/11/2012&Hora=&NumADT=1&NumCHD=0&NumINF=0&SomenteDireto=0&Cia=&SelCabin=&utm_source=&utm_medium=&utm_campaign=&CPId=");
Document doc = Jsoup.parse(url, 100000);
String title = doc.title();
System.out.println(doc.toString());
If I try to see the source code via Mozilla Firefox the values disapears too.
But If I use the firebug plugin I can see them.
Thank's for the help!
The website uses JavaScript to populate all of the values you are trying to parse. You will have to use a library that can compute the javascript within the page. Not sure if there is one though.
anyone else?
Htmlunit is a headless browser that renders Javascript and should be able to present this page correctly.
HtmlUnit for Java is great but I haven't been able to figure out how to view the full source or return the source of a web site as a string. can anyone help me with this?
I know the follow will read the site but now I just want to return the source to a string.
HtmlPage mySite = webClient.getPage("http://mysite.com");
Thanks!
From looking through the API, my thought would be:
mySite.getWebResponse().getContentAsString();
String pageSource = myPage.asXml();
That will get you the full HTML source of the web page.
String pageText = myPage.asText();
That will get you all of the visible text on the page, including line breaks/white space. It would be the same if you were on the page in your browser and Ctrl+A then Ctrl+V into a variable.
have you tried mySite.asXml()? Or you can do mySite.getDocumentElement().toString()