Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading hyperlink in excel through Java

 
purnima Nair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using JExcel API to read excel in java.
Now the excel contains a column with hyperlinks.I need to read the contents(html file) of that hyperlink and put into another text file.

Is there any way in java where we can read the hyperlink content without actually clicking the link in the excel.

Please help.
Thanks,
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See java.net.URL.getContent(). What it returns is implementation-specific, but most likely an InputStream.
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URL.openStream() will definitely return an InputStream.
 
purnima Nair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply...
I used the following code to get the contents of the link
URL url = new URL("http://www.google.com");
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestProperty("User-Agent", "");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
System.out.println(str);
}
in.close();
But,it is giving error java.net.UnknownHostException: www.google.com
I am working on the LAN.If i exceute the same code outside LAN its working..What could be wrong?

Thanks,
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. Your code is too difficult to read without code tags.
 
purnima Nair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is as below:


Am getting java.net.UnknownHostException: www.google.com
 
Sandeep Sanaboyina
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may need a proxy for connecting. Use this code for setting the proxy

Hope it helps.
 
purnima Nair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not working even by setting the proxy by using

I am able to connect to www.google.com without the proxyHost from the LAN.But when I connect using


Its gives unknownHostException in the above line.
 
Sandeep Sanaboyina
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, The following code worked for me.And when I commented out the 2 System.setProperty lines, I got an java.net.UnknownHostException: www.google.com
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
purnima Nair wrote:Its not working even by setting the proxy by using

you did replace these values with your company's proxy settings, right?

I am able to connect to www.google.com without the proxyHost from the LAN.

Do you mean from your browser? Are you sure that there is no proxy filled in for you?

If you open a command window and type in "ping www.google.com", can it resolve the host name?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic