Author Topic: How to mimic a web browser using Jsoup?  (Read 1314 times)

0 Members and 1 Guest are viewing this topic.

Offline Fam5AHcno5

  • NULL
  • Posts: 1
  • Cookies: 0
    • View Profile
How to mimic a web browser using Jsoup?
« on: July 30, 2015, 09:15:32 pm »
First of all, I checked this link:
http://stackoverflow.com/questions/7797386/how-to-mimic-a-web-browser-from-java-using-jsoup
But I don't think this question has a complete answer. I'm writing a bot for an online game, and I want to mimic Firefox exactly. Right now the methods that I'm utilizing are:

Code: [Select]

        browsedCon = Jsoup.connect(myURL)
                .userAgent(firefoxUserAgent)
                .referrer(myCurrentURL)
                .cookies(myCookies)
                .followRedirects(true)
                .timeout(1000)
                .method(Connection.Method.GET)
                .execute();

myCookies are the cookies from he previous page. I'm fairly certain that this is not how Firefox works, so I definitely need some improvement there. I think I might be missing the cookies from the redirected page.
Also, I'm downloading images referred in the html document, at the beginning of my browsing session. What else should I consider to make my code completely unnoticeable?
 

Offline poklocal

  • NULL
  • Posts: 1
  • Cookies: 0
    • View Profile
Re: How to mimic a web browser using Jsoup?
« Reply #1 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");

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: How to mimic a web browser using Jsoup?
« Reply #2 on: August 25, 2015, 08:47:17 am »
What else should I consider to make my code completely unnoticeable?

Well timing is one thing, a human being can only click/type/read/decide so fast and to what appears to be random timing.
If it is human behaviour you are seeking to mimic I suggest you randomize timing on certain functions.
Google is a great example of such an effect, ever had to fill in capcha's ?
Too many ,what might be recognized as automated requests, either too frequent or with too short a interval, it is detectable.

« Last Edit: August 25, 2015, 08:51:45 am by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage