I can't create a session using jsoup and how to post the data using jsoup
. Please help me, I'm new to jsoup api
, actually my code is:
Connection.Response res = Jsoup.connect("https://wiki.my---------------")
.userAgent("Mozila")
.timeout(0)
.method(Method.GET)
.execute();
Document docu = res.parse();
Map<String, String> cookies = afterLogin.cookies();
Document doc2 = (Document) Jsoup.connect("https://wiki.my------------------")
.data("os_username", "A57", "os_password", "pass")
.data("login", "Log on")
.cookies(cookies)
.timeout(0)
.post();
I get one webpage (doc2)and then add to some table to that webpage (doc2)?
How to add new data already existing web page doc2 and then how to post doc2 to anther url
. Already tried a lot, please help me.
For using jsoup to login to any website and retrieving and Parse the data from this website, you just need to follow the bellow instructions:
First point you need to know what is the name of cookies ( Session Name) that you will use it to login to all pages of site.
NOTE: you can know the Session Name of any website as bellow: Login to your website that you want to know the Session Name or cookies for it Then write in URL field this command
javascript:void(alert(document.cookie))
copy the session name then do this
Response res = Jsoup.connect("login Site URL")
.method(Method.GET)
.timeout(10000)
.execute();
String sessionID = res.cookie("SESSION ID for site");//here put the Session Name for website
now you have the Session Name of website but still you need to fill it with your login info
String username="your username";
String password="your pass";
Jsoup.connect("login Site URL")
.data("login:username", username, "login:password", password, "login:loginImg", "", "login", "login")
.cookie("SESSIONID", sessionID)
.method(Method.POST)
.timeout(10000)
.execute();// now you have filled the Session Name with your login info and you can use it for any page in website
Document doc = Jsoup.connect("any page of site")
.cookie("SESSIONID", sessionID)
.timeout(10000)
.get();// her to open any page with Session
Name that you already have it
now you just need to go to the tag or element that you need to get your data from it
System.out.println(doc.body().text());// for print all text in page
or if you have element ID you can get data like this
String S = doc.select("span[id^=here put element id]");
System.out.println(S);
or like this
String S=doc.getElementById("ElementID").text();
System.out.println(S);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With