0

Okay, I'm a total noob to stack overflow so please forgive me if I do something wrong :3.

I am using java EE in eclipse mars and I would like to retrieve a response from a website like Definition Lookup or google dictionary (http://google-dictionary.so8848.com/).

From what I understand I would have to send a request through the URL using a format similar to this google-dictionary.so8848.com/meaning?word="Word to lookup"

What I don't know, or understand is how exactly to go about that, thanks in advance to anyone willing to answer this <3

pie pies
  • 3
  • 2

1 Answers1

0

What you want here is called web scraping, you can accomplish that with multiple frameworks but I recommed Jsoup because it is the easiest one.

Here is a quick example using Jsoup:

First: Download Jsoup jar file:

Or if you are using Maven add it to POM.xml

<dependency>
  <!-- jsoup HTML parser library @ https://jsoup.org/ -->
  <groupId>org.jsoup</groupId>
  <artifactId>jsoup</artifactId>
  <version>1.10.3</version>
</dependency>

Second:: Connect to website you want:

Document doc = Jsoup.connect("google-dictionary.so8848.com/meaning?
word="Word to lookup"").get();

Third: Parse and find elements you want from the returning HTML:

Elements newsHeadlines = doc.select("Element you want");
Fady Saad
  • 1,169
  • 8
  • 13
  • Thanks for the help, you saved my butt. One last quick question, how do I find the name of an element in an HTML page (I'm not particularly fluent in HTML and I only kind of know what that means) – pie pies Jun 19 '17 at 01:35
  • You have two options, either select by tag name like:
    div is the name or get it by unique value like(name, id, class) ex:
    all of this using Css-like selectors ex: Elements newsHeadlines = doc.select("div[name=myname]");
    – Fady Saad Jun 19 '17 at 01:40
  • oh wait one more thing, which document import should I be using, because I'm using the Jsoup one and it's throwing a fit (Unhandeled IOException error, which I have no clue what means) – pie pies Jun 19 '17 at 01:55
  • See this [answer](https://stackoverflow.com/questions/2305966/why-do-i-get-the-unhandled-exception-type-ioexception) for details. – Fady Saad Jun 19 '17 at 02:01