java - jsoup posting and cookie -


i'm trying use jsoup login site , scrape information, running in problem, can login , create document index.php cannot other pages on site. know need set cookie after post , load when i'm trying open page on site. how do this? following code lets me login , index.php

document doc = jsoup.connect("http://www.example.com/login.php")                .data("username", "myusername",                       "password", "mypassword")                .post(); 

i know can use apache httpclient don't want to.

when login site, setting authorised session cookie needs sent on subsequent requests maintain session.

you can cookie this:

connection.response res = jsoup.connect("http://www.example.com/login.php")     .data("username", "myusername", "password", "mypassword")     .method(method.post)     .execute();  document doc = res.parse(); string sessionid = res.cookie("sessionid"); // need check right cookie name 

and send on next request like:

document doc2 = jsoup.connect("http://www.example.com/otherpage")     .cookie("sessionid", sessionid)     .get(); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -