Solved

Reading an HTML page

Posted on 2003-11-17
4
261 Views
Last Modified: 2010-04-01
I currently have a system which works through JSPs. I wish to integrate this system with another thirtd party system. Basically what happens is that I 'call' a url, e.g. www.test.com?AD=1&AB=2. This url would then return an HTML page containing a table. I want to read the contents of this table as it contains parameters I need to use for further processing. The table would contain a number of columns each cell of which would contain certain info, e.g. AB=5. I would want to know that AB is 5

Any ideas how I go about this?

Thanks
0
Comment
Question by:Ktoshni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 250 total points
ID: 9763967
You'll need to URLConnection to get the html from other site. and then parse the html to extract what you need.

Sample of using URLConnection:

        URL url = new URL( "http://www.test.com?AD=1&AB=2" );
        URLConnection conn = url.openConnection();
        InputStream in = new BufferedInputStream( conn.getInputStream() );
        // read html content from the input stream.

You can manually parse the html content by search for particular string pattern. or you can also make use of javax.swing.text.html and javax.swing.text.html.parser package. I'm not an expert of those packages but there is a lot example available in google.
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 9769092
I suggest you to use HttpUnit or HtmlUnit (you can find both on sorceforge.net)
package to parse it. This packages were designed for testing - but they are very good for working with HTML struture, they can load HTML page from specified URL and give you very clear and simple object model of this HTML page, so you can easily get values you want.
0
 

Author Comment

by:Ktoshni
ID: 9769502
Thanks for the help kennethxu. I tried using the code you gave me but I forgot to mention that I need to connect to a secure server through HTTPS. When I try to create the URL instance it is a failing with the error: 'Malformed URL Exception unknow protocol: https'

Is there a way I can set URL to accept https or must I use something else?

On another note, thanks for the info dualsoul but the system I am working on is a production system and I can only use programs accepted by my company.
0
 

Author Comment

by:Ktoshni
ID: 9770021
Hi I sorted the https problem by using HttpsURLConnection. Forgive my ignorance but how do I go about reading the HTML content from the input stream?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jersey maven project error 7 152
struts hibernate integration example 28 157
spring JDBC Template example error 26 356
How can I   ajax html table  rows? 20 88
The following article is comprised of the pearls we have garnered deploying virtualization solutions since Virtual Server 2005 and subsequent 2008 RTM+ Hyper-V in standalone and clustered environments.
Check out this step-by-step guide for asking an anonymous question on Experts Exchange.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question