-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUCSBCurriculumSearch.java
107 lines (61 loc) · 3.12 KB
/
UCSBCurriculumSearch.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package mytestpack;
//import org.apache.commons.lang3.ArrayUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import com.google.common.base.Strings;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.swing.text.html.HTML;
import org.jsoup.*;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class UCSBCurriculumSearch {
public static ArrayList<String> lectures = new ArrayList<String>();
public static ArrayList<String> loadCourses()
{
WebDriver driver = new FirefoxDriver();
driver.get("https://my.sa.ucsb.edu/public/curriculum/coursesearch.aspx");
String [] subject = {"ANTH" , "ART", "ART CS", "ARTHI", "ARTST", "AS AM", "ASTRO", "BIOL",
"BIOL CS", "BMSE","BL ST", "CH E", "CHEM CS", "CHEM", "CH ST", "CHIN", "CLASS",
"COMM", "C LIT", "CMPSC", "CMPSCCS", "CMPTG", "CMPTGCS", "CNCSP", "DANCE", "DYNS",
"EARTH", "EACS", "EEMB", "ECON", "ED", "ECE", "ENGR", "ENGL", "ESM", "ENV S", "ESS",
"ES", "FEMST", "FAMST", "FLMST", "FR", "GEN S", "GEN SCS", "GEOG", "GER", "GPS", "GLOBL",
"GREEK", "HEB", "HIST", "INT", "INT CS", "ITAL", "JAPAN", "KOR", "LATIN", "LAIS", "LING",
"LIT", "LIT CS", "MARSC", "MATRL", "MATH", "MATH CS", "ME", "MAT", "ME ST", "MES",
"MS", "MCDB", "MUS", "MUS CS", "MUS A", "PHIL", "PHYS", "PHYS CS", "POL S", "PORT", "PSY", "RG ST",
"RENST", "SLAV", "SOC", "SPAN", "SHS", "PSTAT", "TMP", "THTR", "WRIT", "W&L", "W&L CS"};
int deptSize = subject.length;
//Select depts = new Select(driver.findElement(By.id("ctl00_pageContent_courseList")));
// index 87 = pstat
String [] qrtrs = {"FALL 2016"," SUMMER 2016","SPRING 2016","WINTER 2016","FALL 2015","SUMMER 2015", "SPRING 2015","WINTER 2015", "FALL 2014","SUMMER 2014", "SPRING 2014"};
int qrtrSize = qrtrs.length;
Select qrtr = new Select(driver.findElement(By.id("ctl00_pageContent_quarterList")));
//index 1 is summer
qrtr.selectByIndex(0);
int indexOfSelectedqrtr = 0;
for(int i =0; i < deptSize; i++){
Select depts = new Select(driver.findElement(By.id("ctl00_pageContent_courseList"))); //need to do this here idk why
depts.selectByIndex(i);
//depts.selectByIndex(i);
//qrtr.selectByIndex(0);
driver.findElement(By.id("ctl00_pageContent_searchButton")).click(); //click search
//int size = tr.size();
String html = driver.getPageSource(); //get html as a stringn
Document doc = Jsoup.parse(html); //create doc?
doc.select("tr.CourseInfoRow").select("div").remove();
String tds = doc.select("tr.CourseInfoRow").text();
System.out.println(tds);
lectures.add(tds);
}
return lectures;
}