GitBucket
4.20.0
Toggle navigation
Sign in
Files
Branches
1
Tags
Issues
4
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
Jonathan
/
KA-Visual
Browse code
Added searchText.
master
1 parent
4f01e25
commit
39e3d7b88a318fe37eb28e9eda95188d019abfcb
Jonathan Ström
authored
on 21 Feb 2017
Patch
Showing
1 changed file
src/getUrlResults.java
Ignore Space
Show notes
View
src/getUrlResults.java
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), searchText); } public static List<String> getWordsList(List<String> linesList, String searchText) { 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; } }
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; } }
Show line notes below