Wget: How do I keep cookies session alive for recursive or mirror download (--keep-session-cookies not working)
Asked Answered
A

1

6

I'm trying use wget to download a website but it does not keep it session alive after the first Webpage its cloned, the website has a login and uses HTTPS so I wont be able to navigate trough it if its not by credentials. I managed to log into the server using cURL and saving it PHPSESSIONID into a cookie.txt So this proccess I'm doing:

First, I create a cookie.txt

wget --save-cookies=cookie.txt 
     --keep-session-cookies "https://huellas.dashboardtimes.com/login.php?user=MyUserName&password=MyPass"
     --delete-after

No --post-data its given since the website uses a GET method to authenticate (this logs in successfully but just for the first page).

And then:

wget --load-cookies=cookie.txt -m https://Website.wget.com/home

At this point, wget clone https://Website.wget.com/home after a successful login in it with returned code 200 OK, but when it finishes /home and enters to another module like for example https://Website.wget.com/contacts it looses it's session and clone all others modules as an Error - 404 with a return code 302. I also tried to give the command a list with a couple of URLS

wget --load-cookies=cookie.txt -m -i list.txt

But I'm still getting the same results. Is there something in the -m option that could cause this? Because if I don't specify the -m option it does download the HTML file of the URLS in the list with no Error 404, but I need more than just the HTML so that why I'm using -m option.

Is there a workaround for this or am I missing something?

(If there's any other tool like wget that I can use for this I would like to know also).

Thanks for your answers.

Anzus answered 26/6, 2020 at 7:39 Comment(1)
I have the same problem. Even when I don't use the -m option. The first request works and gives me the logged in content, but the next request, even if it's exactly the same one, doesn't work. The same cookies still work in a browser. Which confuses me even more.Designed
C
0

You can try to reject the logout page:

--reject logout.php
Chalky answered 4/9, 2024 at 20:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.