if (unparsed.trim().equals("-r")) {
unparsed = "Special:Random";
}
try {
Connection con;
url = new URLBuilder("http://en.wikipedia.org/w/index.php");
url.setParameter("search", unparsed);
while (true) {
con = Jsoup.connect(url.toString());
con.followRedirects(false);
con.execute();
if (con.response().statusCode() == 200) {
doc = con.response().parse();
break;
} else if (con.response().statusCode() == 302) {
url = new URLBuilder(con.response().header("Location"));
} else {
channel.write("Could not find page");
return;
}
}