4

I want to grab the source code of a page which contains the word "true" or "false". That's the only two words that would be on that page, no other formatting.

So I just need Java to URL connect to that page "http://example.com/example.php" and just grab the contents.

2
  • Do you mean "download content by url into a Java class"? Commented Apr 3, 2011 at 1:52
  • @Jared Farrish - Yeah, pretty much. Basically getting a page's content using the URL class. Commented Apr 3, 2011 at 2:10

2 Answers 2

6

Try this tutorial : Java URL example - Download the contents of a URL

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks so much for the find. I was searching for hours on google so I guess I was using the wrong keywords. Not sure if I'll succeed in following the tutorial though, since I'm new to Java.
@Fallen Angel - If it's really what you need, remember to click the outlined "checkmark" next to this answer to accept it as the most appropriate answer for you question.
Don't hesitate to ask if you fail to find a good solution to one specific part, though. We still beginner in the end!
@Jared Farrish - I want to click it lol but it said I have to wait 8 minutes xD
That's to discourage spammers and malcontents.
|
2

There is an easy way to do that using Apache Commons IO. For example for mentioned action you can just write

URL url = new URL("http://example.com/example.php");
String content = IOUtils.toString(new InputStreamReader(
                        url.openStream()));

2 Comments

Eclipse asks to create a new class "IOUtils" !! So google gives me the class at devdaily.com/java/jwarehouse/commons-io-1.0/src/java/org/apache/… Creating this class make Eclipse asks again for a new class "CopyUtils" !!!
You have to download commons-io-2.0.1.jar from commons.apache.org/io/download_io.cgi and include it in the classpath. No need for creating new classes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.