Skip to content

Instantly share code, notes, and snippets.

@dotspencer
Last active May 17, 2016 15:55
Show Gist options
  • Select an option

  • Save dotspencer/49d4c5ac28f94bfec677a9f3665d3aec to your computer and use it in GitHub Desktop.

Select an option

Save dotspencer/49d4c5ac28f94bfec677a9f3665d3aec to your computer and use it in GitHub Desktop.
Test for loading project pages for the status checker program
package testing;
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
import org.jsoup.HttpStatusException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Test {//https://egi.utah.edu/all/
public static void main(String[] args) {
String projects = "";
Document doc;
try {
doc = Jsoup.parse(new URL("http://egi.utah.edu/all/"), 10_000);
Elements links = doc.select("#projects a");
for(Element link : links){
String[] temp = link.attr("href").split("/");
projects += temp[temp.length - 1].toUpperCase() + "\n";
}
//System.out.println(projects);
} catch (IOException e) {
e.printStackTrace();
}
Scanner s = new Scanner(projects);
while(s.hasNextLine()){
String num = s.nextLine();
load(num);
}
s.close();
}
public static void load(String num){
int timeout = 10000;
try {
Document doc = Jsoup.parse(new URL("http://egi.utah.edu/research/current-projects/" + num), timeout);
Elements title = doc.select("h1 > span + span");
if(num.length() < 7){
num += " ";
}
System.out.println(num + " " + title.text());
} catch (IOException e) {
if(e instanceof HttpStatusException){
return;
}
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment