Created
October 18, 2014 09:35
-
-
Save wololock/568b9cc402ea661de546 to your computer and use it in GitHub Desktop.
Retrieving table data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jsoup.Jsoup | |
import org.jsoup.nodes.Document | |
import org.jsoup.nodes.Element | |
@Grab(group='org.jsoup', module='jsoup', version='1.8.1') | |
String url = 'http://www.sportinglife.com/greyhounds/abc-guide' | |
Document document = Jsoup.connect(url).get() | |
List<Element> rows = document.select('table[id=ABC Guide] > tbody > tr') | |
Map<String, String> data = new HashMap<>() | |
for (Element row : rows) { | |
String dog = row.select('td:eq(0)').text() | |
String race = row.select('td:eq(1)').text() | |
data.put(dog, race) | |
} | |
assert !data.isEmpty() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment