What I need to write is a code snippet that would go to a website e.g. www.google.com find the search box put in the phrase and retrieve HTML code of results page/pages. Is it possible to achieve this in Java?
5 Answers
e.g. www.google.com
For Google, use the JSON/Atom Custom Search API. It is the only (legal) way to access Google search.

- 168,117
- 40
- 217
- 433
Yes, use something like HttpClient, although there are other similar options.

- 158,873
- 26
- 254
- 302
Most probably you should be able to pass a parameter to the url (have a look at the google url after issuing a search, there are plenty of parameters) or use a post request (if the site supports it, check for an API description).
If you read the URL directly from Java (e.g. using the URL
class) you'll get the returned HTMl as is.

- 87,414
- 12
- 119
- 157
The first tool I thought of was Selenium. It is primarily a web testing framework, but can be used to automate a browser for the kind of operation you're suggesting.
http://seleniumhq.org/docs/03_webdriver.html#getting-started-with-selenium-webdriver

- 3,743
- 1
- 25
- 41
HttpUnit can also be used. It's a well documented, open source and easy to use unit test framework.

- 180
- 1
- 6