I want to use Jsoup to crawl a page that is only available when I signed in. I guess it means I need to sign in on one page and send cookies to another page.
I read some earlier post here and write the following code:
public static void main(String[] args) throws IOException {
Connection.Response res = Jsoup.connect("login.yahoo.com")
.data("login", "myusername", "passwd", "mypassword")
.method(Method.POST)
.execute();
Document doc=res.parse();
String sessionId = res.cookie("SESSIONID");
Document doc2 = Jsoup.connect("http://health.groups.yahoo.com/group/asthma/messages")
.cookie("SESSIONID", sessionId)
.get();
Elements Eles=doc2.getElementsByClass("message");
String content=Eles.first().text();
System.out.println(content);
My question is how I can know my cookie name (i.e. "SESSIONID") here for sending my login info? I used the .cookies() method to get all the cookies from the login page:
B
DK
YM
T
PH
Y
F
I tried them one by one but none worked. I could get sessionId from some of them, but I could not successfully get nodes from the second page, which means I didn't successfully sign in. Could anyone give me some suggestions? Many thanks!