
January 31st, 2002, 12:40 PM
|
|
Junior Member
|
|
Join Date: Jan 2002
Posts: 0
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
in case anyone cares.....
i found a way to do it in Java
the following is some sample code:
<%
// if i want to get the present price of a book with isbn number
//0062514792 from barnesandnoble.com i would do the collowing
//in my JSP page
String url = "http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=0062514792";
URL u = null;
HttpURLConnection urlc = null;
// Open a connection to a specified URL
try {
u = new URL (url);
}
catch (MalformedURLException mfurle) {
System.err.println ("URL: " + url + "\t\tMalformed URL " + mfurle.getMessage());
}
catch (Exception e) {
System.err.println ("URL: " + url + "\t\tException: " + e.getMessage());
}
// create HttpURLConnection object and then connect to the page
try {
urlc = (HttpURLConnection)u.openConnection ();
}
catch (UnknownHostException uhe) {
System.err.println (url + "\tUnknown Host " + uhe.getMessage());
}
catch (NoRouteToHostException nrthe) {
System.err.println (url + "\tNo Route to Host " + nrthe.getMessage());
}
catch (Exception e) {
System.err.println (url + "\tException " + e.getMessage());
}
// Define some HTTP header information about yourself
urlc.setRequestProperty ("User-Agent:", "just-a-test-v1.0");
urlc.setRequestProperty ("From:", "me@myaddress.edu");
// Now we can connect and start loading the page
try {
urlc.connect ();
}
catch (IOException ioe) {
System.err.println ("Connection Failure " + url + "\tException: " + ioe.getMessage());
}
// Load page contents using a buffered reader and the URLConnection.getInputStream()
// method. You should use this technique for first loading the robots.txt file for
// the site. If it exists, pay attention to it!
String line;
BufferedReader br = new BufferedReader (new InputStreamReader (urlc.getInputStream ()));
while ( (line = br.readLine ()) != null ) {
if (line.trim().startsWith("Our Price:")){
out.write("TRUE\n");
out.write(line+"\n");
}
}
// Close the stream when you're done, and then disconnect
br.close ();
urlc.disconnect ();
%>
|