import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; public class getUrlResults { public static List<String> getSearchResults(String searchText) { return getWordsList(downloadUrl(searchText)); } public static List<String> getWordsList(List<String> linesList) { List<String> resultList = new ArrayList<String>(); boolean passedLine = false; for (String line : linesList) { if (line.contains("<a class='detailslink' href='Details.aspx?word=") && line.contains("'>Visa mer information om <strong>")) { passedLine = true; } if (passedLine) { System.out.println(line); resultList.add(line); } } return resultList; } public static List<String> downloadUrl(String searchWord) { List<String> lines = new ArrayList<String>(); URL url; InputStream is = null; BufferedReader br; String line; try { url = new URL("http://www.kryssakuten.se/Search.aspx?stype=ord-som-matchar-monster&sword=" + searchWord); is = url.openStream(); // throws an IOException br = new BufferedReader(new InputStreamReader(is)); while ((line = br.readLine()) != null) { lines.add(line); System.out.println(line); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (IOException ioe) { // nothing to see here } } return lines; } }