Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use java to gather online information

Status
Not open for further replies.

jasonwyz98

Programmer
Nov 24, 2003
11
US
Hello

What i want to do is provide the application with a set of urls, have the app gather some data (i.e. pricing, product list, etc) automatically.

ex. give the app a url address and have the app gather the price data on certain products.

Please be specific and what' the easiest way to acommplish this.

thanks
 
The first place to start is to use the HttpUrlConnection class to download the data. See these threads :

thread269-715471
thread269-845295

--------------------------------------------------
Free Database Connection Pooling Software
 
Code:
String[] arrayOfUrls = {"[URL unfurl="true"]http://www.example.com/",[/URL] "[URL unfurl="true"]http://www.example.com/2.html"};[/URL]

String[2] pages;

for(int i = 0; arrayOfUrls.length > i; ++i)
{
   URL url = new URL(arrayOfUrls[i]);
   pages[i] = (String)url.getContent();
}
To get a stream and parse the data a bit better you'd want to use openConnection() of the URL class. The http:// is important because it tells the URL what kind of a connection to make, and the line
Code:
url.getContent()
is just short hand for
Code:
url.openConnection().getContent()
-- Also the snipit above doesn't catch IOExceptions or MalformedURLExceptions which need to be handled or passed on.
 
Personally I prefer to directly control the downloading of data by hand using the IO sockets from HttpUrlConnection class, because it gives you more control, and saves the hassle of dealing with the "Object" returned from the getContent() method.

--------------------------------------------------
Free Database Connection Pooling Software
 
Generally I do too, unless I'm just dumping it to a JEditPane.

Since we're on the subject... Is what event occured (i.e. key press, right click, left click) inside of a HyerlinkEvent? I can get entered/exit information... but any click is looked at as an ACTIVATED.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top