09-20-2012 11:36 AM
Hi,
Fisrtly i'm a french student so sorry for my bad level in english... I would like to do an application that recover information on a web site, for this I want to recover a html page into a string, after this, i cut the string in order to recover specific information.
My question is : How can I get html code of a web page into a String ?
In Java i can, but with Blackberry JDK I don't know,
Waiting for your answer.
Courtial Florian
Solved! Go to Solution.
09-20-2012 11:53 AM
09-20-2012 01:35 PM
Thank you, I will try soon ![]()
09-20-2012 07:25 PM
I use the following method where the paramter passed in is your url.
private static String GetPageText(String text)
{
ConnectionFactory factory = new ConnectionFactory();
ConnectionDescriptor conDescriptor = factory.getConnection(text);
try
{
StreamConnection s = (StreamConnection) conDescriptor.getConnection();
InputStream input = s.openInputStream();
byte[] data = new byte[256];
int len = 0;
StringBuffer raw = new StringBuffer();
while ( -1 != (len = input.read(data)) )
{
raw.append(new String(data, 0, len));
}
text = raw.toString();
input.close();
s.close();
}
catch (Exception e) {return "";}
return text;
}
09-21-2012 02:48 AM
09-21-2012 05:45 AM
I try, but I have a problem.
This is my code :
public void loadCodeSource (String url) {
String text = null;
ConnectionFactory factory = new ConnectionFactory();
ConnectionDescriptor conDescriptor = factory.getConnection(url);
try
{
StreamConnection s = (StreamConnection) conDescriptor.getConnection();
InputStream input = s.openInputStream();
byte[] dataTest = IOUtilities.streamToBytes(input);
text = new String(dataTest);
//In order to see the result
UiApplication.getUiApplication().pushGlobalScreen( new Dialog(Dialog.OK,text.substring(0, 100),Dialog.OK,null,Dialog.GLOBAL_STATUS),500,UiEn gine.GLOBAL_QUEUE);
input.close();
s.close();
this.setCodeSource(text);
}
catch (Exception e) {
UiApplication.getUiApplication().pushGlobalScreen( new Dialog(Dialog.OK,"No network...",Dialog.OK,null,Dialog.GLOBAL_STATUS),5 00,UiEngine.GLOBAL_QUEUE);
}
}And my string text is empty, i think the connection fails...
09-21-2012 05:53 AM
09-21-2012 06:29 AM
I find the problem, i had a bad URL ![]()
Thank you very much for your help,
I close the subject...
09-21-2012 06:34 AM
For my test I used StreamConnection but I will use HTTPConnection because I have to connect to a website in order to get information.
Thank you.
09-21-2012 08:42 AM
I have a new problem, i d'ont open a new topic because my problem concerns HTML code. When I recover the code on the website, I recover nothing.
Indeed I try to recover HTML code on a dynamic page. This is a page generated by a JavaServer. (The page is a .jsp).
When the HTML code is recover, the JavaServer has not yet created the page.
So how can I recover HTML code ?
Waiting for your answer,
Courtial Florian