This forum is in archive mode. You will not be able to post new content.

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - poklocal

Pages: [1]
1
Java / Re: How to mimic a web browser using Jsoup?
« on: August 25, 2015, 08:31:43 AM »
I think you'll find the HtmlUtil library useful:


Code: [Select]
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setRedirectEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getCookieManager().setCookiesEnabled(true);

final HtmlPage facebook = webClient.getPage("http://www.facebook.com");

final HtmlForm form = (HtmlForm) facebook.getElementById("login_form");

//Filling out the form
final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Log In").get(0);
final HtmlTextInput textField = (HtmlTextInput) facebook.getElementById("email");
textField.setValueAttribute("email@email.com");
final HtmlPasswordInput textField2 = (HtmlPasswordInput) facebook.getElementById("pass");
textField2.setValueAttribute("password");

//Logging in:
HtmlPage loggedin = button.click();
System.out.println("logged in");

Pages: [1]


Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.