Answer the question
In order to leave comments, you need to log in
How to open a page in JAVA, enter a login and password, and after logging in, download a file?
You need to go to the /accounts/login/
page , enter your login and password. After logging in, download the file from the link /file/ .
<form action="/accounts/signin/" method="POST">
<p><b>Введите логин</b></p>
<p><input type="text" name="form[login]" onclick="if (this.value == 'личный № организации') this.value='';" onblur="if (this.value == '') this.value='Поиск по сайту';" value="личный № организации" style="background:url('/images/men.png') no-repeat scroll 7px 3px transparent;padding-left:30px;"></p>
<p><b>Введите пароль</b></p>
<p><input type="password" name="form[password]" onclick="if (this.value == 'личный № организации') this.value='';" onblur="if (this.value == '') this.value='Поиск по сайту';" value="личный № организации" style="background:url('/images/key.png') no-repeat scroll 7px 3px transparent;padding-left:30px;"></p>
<p> </p>
<input type="submit" value="Войти в кабинет">
Connection.Response loginForm = Jsoup.connect("http://site/accounts/login/")
.method(Connection.Method.GET)
.execute();
Document doct = Jsoup.connect("http://site/accounts/login/")
.data("cookieexists", "false")
.data("form[login]", "LOGIN")
.data("form[password]", "PASSWORD")
.cookies(loginForm.cookies())
.post();
Answer the question
In order to leave comments, you need to log in
I think Selenium WebDriver will suit you, it is used for automated testing.
Jsoup is a parser. He won't help you. Because submitting form data is a request, then you need to manipulate the request. This can be done using Apache HttpClient , for example...
Try like this:
Response res = Jsoup
.connect("/url/to/login")
.data("input[login]", "admin")
.data("input[pass]", "QWERTY1234")
.method(Method.POST)
.execute();
Document doc = res.parse();
Document doc2 = Jsoup
.connect("/url/to/file")
.cookies(res.cookies())
.get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question