akzah
asked on
Parsing a String (BufferReader)
Hi
I am using the following code and a bit more to download a html file from a website and it is then turned into a string.
URLConnection connection = javacodingURL.openConnecti on();
BufferedReader br = new BufferedReader(newInputStr eamReader( connection .getInputS tream()));
String line = "";
while ((line = br.readLine()) != null)
System.out.println(line);
br.close();
My code works, and I get a ouput of the html file. Though what I want is specfic text but I don't want to use the HTMLEditor from java as it causes too many problems. The html file has some code at the start which I want to ignore and it then follows a pattern:
It starts with <p align="center">........... .(code I need)......<hr color="#87A9DC">. Then again it starts with <p align="center">........... .(code I need)......<hr color="#87A9DC"> (goes on in that format till then end)
My question is how would I get the all the html code between the p align code and hr color and place the data individualy into a arraylist?
Thanks for any help
Akbar
I am using the following code and a bit more to download a html file from a website and it is then turned into a string.
URLConnection connection = javacodingURL.openConnecti
BufferedReader br = new BufferedReader(newInputStr
String line = "";
while ((line = br.readLine()) != null)
System.out.println(line);
br.close();
My code works, and I get a ouput of the html file. Though what I want is specfic text but I don't want to use the HTMLEditor from java as it causes too many problems. The html file has some code at the start which I want to ignore and it then follows a pattern:
It starts with <p align="center">...........
My question is how would I get the all the html code between the p align code and hr color and place the data individualy into a arraylist?
Thanks for any help
Akbar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that method sounds good, though how would I get that to work on the BufferedReader br. How would I turn that into a string?
StringBuffer buff = new StringBuffer();
String line = "";
while ((line = br.readLine()) != null)
buff.append(line);
String allTheText = buff.toString();
String line = "";
while ((line = br.readLine()) != null)
buff.append(line);
String allTheText = buff.toString();
Thanks for accepting akzah
:)
That keeps us answering your future questions too.
:)
That keeps us answering your future questions too.
1) Search your string for "<p align="center">"
2) From that place search for "<hr color="
3) Get that in between.
The function String.indexOf() will be useful:
int indexOf(String str, int fromIndex)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.