当我尝试使用Jsoup整理大学网站时,它没有填写网站中的表格。但是,当我使用具有相同凭据的浏览器登录网站时,其登录页面。 我也给了useragent cookie。 这是我第一次使用jsoup。 我尝试了所有使用jsoup的方法 请帮助我登录页面 oncreate bundle将执行以下操作
new C4977c().execute();
//enter captcha and onclick
//onclick button
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
captcha=e.getText().toString();
//setting captcha to string
Log.d("captcha",captcha);
new C4977d().execute();
}
});
}
public class C4977c extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
String str;
//The below code creates a connection to website and gets the captcha with cookies of the connection.
//Then user enter the captcha
DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
int i = 0;
defaultHttpClient.execute(new HttpGet(login url));
CookieStore cookieStore = defaultHttpClient.getCookieStore();
BasicHttpContext basicHttpContext = new BasicHttpContext();
basicHttpContext.setAttribute("http.cookie-store", cookieStore);
Log.d("basic", String.valueOf(basicHttpContext));
Log.d("cookiestore", String.valueOf(cookieStore));
List<Cookie> cookies = cookieStore.getCookies();
String str3 = null;
str2 = null;
for (Cookie cookie : cookies) {
String name = cookie.getName();
str2 = cookie.getValue();
str3 = name;
}
Log.d("str2", str2);
Log.d("str3", str3);
HttpGet httpGet = new HttpGet(captcha url);
//the below is the captcha
defaultHttpClient.execute(httpGet);
bitmap = BitmapFactory.decodeStream(defaultHttpClient.execute(httpGet, basicHttpContext).getEntity().getContent());
Log.d("f18", String.valueOf(bitmap));
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
i.setImageBitmap(bitmap);
//set image captcha
String strs="image";
Log.d("imageset",strs);
//Till this the code works perfect
}
}
public class C4977d extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
Connection.Response f=null;
//the connection is not be created with the following code
//the below connection is not created and response is not generated
f = Jsoup.connect(login url)
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36")
.cookie("JSESSIONID",str2)
.data(data)
.method(Connection.Method.POST)
.followRedirects(true)
.ignoreHttpErrors(true)
.ignoreContentType(true)
.timeout(10000)
.execute();
//its showing the default website page when i use docs
//i am not logged onto the page
Document docsr=Jsoup.connect(enter into page)
.userAgent("Mozilla/5.0")
.cookie("JSESSIONID", str2)
.get();
Log.d("sdd", String.valueOf(docsr));
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
//setting textbox with details
t.setText(docs.text());
}
}
}