Advertisement
Guest User

Skel

a guest
May 28th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public class LeagueCenterRefiner {
  2. public static void main (String args[]) throws IOException {
  3.  
  4. URL url = new URL("http://leaguecenter.net/index.php?action=list&id=QCO84pPmAl");
  5. URLConnection con = url.openConnection();
  6. Pattern p = Pattern.compile("text/html;\\s+charset=([^\\s]+)\\s*");
  7. Matcher m = p.matcher(con.getContentType());
  8.  
  9. String charset = m.matches() ? m.group(1) : "ISO-8859-1";
  10. Reader r = new InputStreamReader(con.getInputStream(), charset);
  11. StringBuilder buf = new StringBuilder();
  12. while (true) {
  13. int ch = r.read();
  14. if (ch < 0)
  15. break;
  16. buf.append((char) ch);
  17. }
  18. String str = buf.toString();
  19.  
  20. System.out.println(Arrays.toString(getTagValues(str).toArray())); // Prints [apple, orange, pear]
  21.  
  22.  
  23. }
  24.  
  25. private static final Pattern TAG_REGEX = Pattern.compile("<td>(.+?)</td>");
  26.  
  27. private static List<String> getTagValues(final String str) {
  28. final List<String> tagValues = new ArrayList<String>();
  29. final Matcher matcher = TAG_REGEX.matcher(str);
  30. while (matcher.find()) {
  31. tagValues.add(matcher.group(1));
  32. System.out.println("[DEBUG] " + matcher.group(1));
  33. }
  34. return tagValues;
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement