+ 1
Paste text content from webpage into java?
First off, I am very new and have little experience. What I want to do with my little code project, is to copy almost everything from an article online into my system.out.println(" here "). However I only get loads of errors, maybe because the text appears on many lines? Idk, appreciate any help :)
3 Réponses
+ 4
Are there any quotes in the text you are trying to copy? That'll mess with the string you're trying to output.
Also keep in mind System has a capitol S.
System.out.println("message");
If it is quotes that are causing the errors you can handle them with the escape character \.
Ex/
System.out.println("A quote: \" ");
Output: A quote: "
(Place \ before the quote you want to output)
0
Thanks for the help, I'll have a look at it! might be some quotes.
0
here is a sample how I did:
URL myurl = new URL("http://example.com/article.html");
String text = "";
Scanner scanner = new Scanner (url.openStream ());
while (scanner.hasNextLine ()){
text += scanner.nextLine ();
}
scanner.close ();
System.out.println (text)