本文整理汇总了Java中com.gistlabs.mechanize.document.html.HtmlDocument类的典型用法代码示例。如果您正苦于以下问题:Java HtmlDocument类的具体用法?Java HtmlDocument怎么用?Java HtmlDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlDocument类属于com.gistlabs.mechanize.document.html包,在下文中一共展示了HtmlDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: selectSchool
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
private HtmlDocument selectSchool(String siteURL, String schoolId) throws SchoolNotFoundException {
MechanizeAgent agent = new MechanizeAgent();
HtmlDocument page = agent.get(siteURL);
Form schoolSelectionForm = page.forms().get(0);
Select schoolDropdown = (Select) schoolSelectionForm.get("PsiId");
List<Select.Option> schools = schoolDropdown.getOptions();
Select.Option schoolOption = null;
for(Select.Option school : schools) {
if (school.getValue().equals(schoolId)) {
schoolOption = school;
}
}
if (schoolOption != null) {
schoolOption.setSelected(true);
}
else {
throw new SchoolNotFoundException();
}
return schoolSelectionForm.submit();
}
示例2: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
/**
* Obtains the raw html of the data.
*
* @return Evalos
*/
public Evalos login() {
try {
final MechanizeAgent agent = new MechanizeAgent();
final Document page = agent.get(WEB_APP_BASE_URL);
Form form = page.form("form1");
form.get("username").set(username);
form.get("password").set(password);
HtmlDocument document = form.submit();
parseRawHtmlResponse(document);
} catch (Exception e) {
connectionProblem = true;
}
return this;
}
示例3: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("aspnetForm");
Text usernameField = (Text) authForm.get("ctl00$ContentPlaceHolder1$UsernameTextBox");
Password passwordField = (Password) authForm.get("ctl00$ContentPlaceHolder1$PasswordTextBox");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument nvitRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = nvitRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例4: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.forms().get(0); // form has no id or name
Text usernameField = (Text) authForm.get("username");
Password passwordField = (Password) authForm.get("password");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument kuRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = kuRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例5: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("login");
Text usernameField = (Text) authForm.get("username");
Password passwordField = (Password) authForm.get("password");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument bcitRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = bcitRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例6: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("aspnetForm");
Text usernameField = (Text) authForm.get("ctl00_ContentPlaceHolder1_UsernameTextBox");
Password passwordField = (Password) authForm.get("ctl00_ContentPlaceHolder1_PasswordTextBox");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument cuRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = cuRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例7: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("fm1");
Text usernameField = (Text) authForm.get("username");
Password passwordField = (Password) authForm.get("password");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument ecuRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = ecuRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例8: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("aspnetForm");
Text usernameField = (Text) authForm.get("ctl00$ContentPlaceHolder1$UsernameTextBox");
Password passwordField = (Password) authForm.get("ctl00$ContentPlaceHolder1$PasswordTextBox");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument dcRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = dcRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例9: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("aspnetForm");
Text usernameField = (Text) authForm.get("ctl00$ContentPlaceHolder1$UsernameTextBox");
Password passwordField = (Password) authForm.get("ctl00$ContentPlaceHolder1$PasswordTextBox");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument vccRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = vccRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例10: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("loginForm");
Text usernameField = (Text) authForm.get("userNameInput");
Password passwordField = (Password) authForm.get("passwordInput");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument lcRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = lcRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例11: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("loginForm");
Text usernameField = (Text) authForm.get("j_username");
Password passwordField = (Password) authForm.get("password");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument ubcRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = ubcRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例12: login
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
@Override
public HtmlDocument login(HtmlDocument authPage, String username, String password, Context context) throws SchoolAuthenticationFailedException {
Form authForm = authPage.form("fm1");
Text usernameField = (Text) authForm.get("username");
Password passwordField = (Password) authForm.get("password");
usernameField.setValue(username);
passwordField.setValue(password);
HtmlDocument sfuRedirect = authForm.submit();
HtmlDocument submittedPage;
try {
HtmlDocument translinkRedirect = sfuRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "translinkRedirect: " + translinkRedirect.getUri());
submittedPage = translinkRedirect.forms().get(0).submit();
LoggerUtil.appendLog(context, "submittedPage: " + submittedPage.getUri());
}
catch (Exception e) {
throw new SchoolAuthenticationFailedException(e);
}
if (submittedPage.getUri().contains("https://upassbc.translink.ca")) {
return submittedPage;
} else {
throw new SchoolAuthenticationFailedException(new Exception("Invalid submitted page URI"));
}
}
示例13: checkUpass
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
private boolean checkUpass(HtmlDocument upassPage) throws NothingToRenewException {
Form requestForm = upassPage.form("form-request");
Checkbox requestCheckbox = null;
for (Object element : requestForm) {
if (element instanceof Checkbox) {
requestCheckbox = (Checkbox) element;
}
}
if (requestCheckbox != null) {
return true;
}
else {
throw new NothingToRenewException();
}
}
示例14: requestUpass
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
private boolean requestUpass(HtmlDocument upassPage) {
List prevRequestedUpasses = upassPage.findAll(".status");
Form requestForm = upassPage.form("form-request");
Checkbox requestCheckbox = requestForm.findCheckbox("input");
requestCheckbox.check();
String boxName = requestCheckbox.getName();
Iterator elementIter = requestForm.iterator();
while (elementIter.hasNext()) {
Object element = elementIter.next();
if (element instanceof Hidden) {
Hidden hiddenElement = (Hidden) element;
if (boxName.equals(hiddenElement.getName())) {
elementIter.remove();
}
}
}
SubmitButton requestButton = requestForm.findSubmitButton("input");
HtmlDocument resultPage = requestButton.submit();
List requestedUpasses = resultPage.findAll(".status");
if (requestedUpasses.size() > prevRequestedUpasses.size()) {
return true;
}
else {
return false;
}
}
示例15: safeGet
import com.gistlabs.mechanize.document.html.HtmlDocument; //导入依赖的package包/类
private HtmlDocument safeGet(MechanizeAgent agent, String url) {
try {
return agent.get(OMAMATKAKORTTI_URL_BASE + url);
} catch (ClassCastException cce) {
// MechanizeAgent throws this if not text/html
throw new MatkakorttiException("Page " + url + " not HTML", cce, true);
}
}