```
<table class="sparql" border="1">
  <tbody><tr>
    <th>simpleProperty</th>
  </tr>
  <tr>
    <td><a href="http://www.wikidata.org/entity/P115c">http://www.wikidata.org/entity/P115c</a></td>
  </tr>
</tbody></table>

```

Using Jsoup, I'm trying to collect all the links from pages that look like [this](http://milenio.dcc.uchile.cl/sparql?default-graph-uri=&query=PREFIX+%3A+%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0D%0ASELECT+*+WHERE+%7B%0D%0A+++%3AQ855+%3FsimpleProperty+%3AQ233999%0D%0A%7D%0D%0A&format=text%2Fhtml&timeout=0&debug=on).

I've been trying many different ways, but I can't seem to pin it down. Most recently I tried like this:

```
// parse the input stream using Jsoup
docx = Jsoup.parse(wiki_relation_InputStream, null, wikidata_relation_page.getProtocol()+"://"+wikidata_relation_page.getHost()+"/");

Element table = doc.select("table").first(); //gets a table with the class "first class"
Elements links = table.select("a[href]");

```

It seems it should be easy because the structure is so minimal, but alas, nevertheless it's causing me a bit of trouble. 

In the case that there is more than one I'd like to collect them all. In the case that there are zero I'd prefer if the program didn't crash in a fireball of death and destruction. 

How to get that elusive link text? (as in `http://www.wikidata.org/entity/P115c` for instance)

Update
------

on the suggestion of panda

```
//get it's normal wiki disambig page
String URL_czech = "http://milenio.dcc.uchile.cl/sparql?default-graph-uri=&query=PREFIX+%3A+%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0D%0ASELECT+*+WHERE+%7B%0D%0A+++%3A" 
        + home + "+%3FsimpleProperty+%3A" 
        + away + "%0D%0A%7D%0D%0A&format=text%2Fhtml&timeout=0&debug=on";

URL wikidata_page = new URL(URL_czech);
HttpURLConnection wiki_connection = (HttpURLConnection)wikidata_page.openConnection();
InputStream wikiInputStream = null;

try 
{
    // try to connect and use the input stream
    wiki_connection.connect();
    wikiInputStream = wiki_connection.getInputStream();
} 
catch(IOException error) 
{
    // failed, try using the error stream
    wikiInputStream = wiki_connection.getErrorStream();
}
    // parse the input stream using Jsoup
    Document docx = Jsoup.parse(wikiInputStream, null, wikidata_page.getProtocol()+"://"+wikidata_page.getHost()+"/");

Elements link_text = docx.select("table.sparql > tbody > tr:nth-child(2) > td > a");
//link_text.text();
for (Element l : link_text) 
{
    String output = l.text();
    System.out.println( output );
}

```

The following thing can get the table but how to drill down farther:

```
Elements tables = docx.select("table.sparql");

for(Element table : tables)
{
     System.out.println(table.toString());
}

```