신문 사이트에 액세스 한 다음 epaper 사본 (PDF)을 다운로드하고 싶습니다. 이 사이트에서 내 이메일 주소와 비밀번호를 사용하여 로그인 한 다음 해당 PDF URL에 액세스 할 수 있습니다.
Wget 에서 '세션 설정'에 문제가 있습니다. 브라우저에서 사이트에 로그인하면 두 가지 쿠키 값이 설정됩니다.
UserID=abc@gmail.com
Password=12345
나는 시도했다 :
wget --post-data "UserID=abc@gmail.com&Password=12345" http://epaper.abc.com/login.aspx
그러나 방금 로그인 페이지를 다운로드하여 로컬로 저장했습니다.
로그인 페이지의 FORM에는 두 개의 필드가 있습니다.
txtUserID
txtPassword
그리고 이와 같은 라디오 버튼 :
<input id="rbtnManchester" type="radio" checked="checked" name="txtpub" value="44">
다른 버튼 :
<input id="rbtnLondon" type="radio" name="txtpub" value="64">
login.aspx 페이지에 게시하면 동일한 결과가 나타납니다.
wget --post-data "txtUserID=abc@gmail.com&txtPassword=12345&txtpub=44" http://epaper.abc.com/login.aspx
만약 내가한다면:
--save-cookies abc_cookies.txt
기본 콘텐츠 이외의 다른 것으로 보이지 않습니다.
마지막으로, 내가 그렇게한다면 --debug
, 그것은 말합니다 :
...
Set-Cookie: ASP.NET_SessionId=05kphcn4hjmblq45qgnjoe41; path=/; HttpOnly
...
Stored cookie epaper.abc.com -1 (ANY) / <session> <insecure> [expiry none] ASP.NET_SessionId 05kphcn4hjmblq45qgnjoe41
Length: 107253 (105K) [text/html]
Saving to: `login.aspx'
...
Saving cookies to abc_cookies.txt.
그러나 abc_cookies.txt는 다음 만 표시합니다.
# HTTP cookie file.
# Generated by Wget on 2011-08-16 08:03:05.
# Edit at your own risk.
(스택 오버플로에서 응답이없는 이유를 잘 모르겠습니다. 수퍼 유저가 더 나은 사이트 일 것입니다. Wget을 사용하여 쿠키를 설정해야하는 사이트에서 PDF 파일을 다운로드하십시오 .)
편집 1
C:\Temp>wget --cookies=on --keep-session-cookies --save-cookies abc_cookies.txt --post-data "txtUserID=abc%40gmail.com&txtPassword=password&txtpub=44&chkbox=checkbox&submit.x=48&submit.y=7" http://epaper.abc.com/login.aspx --debug
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
DEBUG output created by Wget 1.11.4 on Windows-MinGW.
--2011-08-18 08:15:59-- http://epaper.abc.com/login.aspx
Resolving epaper.abc.com... seconds 0.00, 999.999.99.99
Caching epaper.abc.com => 999.999.99.99
Connecting to epaper.abc.com|999.999.99.99|:80... seconds 0.00, connected.
Created socket 300.
Releasing 0x00a2ae80 (new refcount 1).
---request begin---
POST /login.aspx HTTP/1.0
User-Agent: Wget/1.11.4
Accept: */*
Host: epaper.abc.com
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 100
---request end---
[POST data: txtUserID=abc%40gmail.com&txtPassword=password&txtpub=44&chkbox=checkbox&submit.x=48&submit.y=7]
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 200 OK
Connection: keep-alive
Date: Thu, 18 Aug 2011 02:46:17 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Set-Cookie: ASP.NET_SessionId=owcrje55yl45kgmhn43gq145; path=/; HttpOnly
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 107253
---response end---
200 OK
Registered socket 300 for persistent reuse.
Stored cookie epaper.abc.com -1 (ANY) / <session> <insecure> [expiry none] ASP.NET_SessionId owcrje55yl45kgmhn43gq145
Length: 107253 (105K) [text/html]
Saving to: `login.aspx.1'
100%[======================================================================================================================>] 107,253 24.9K/s in 4.2s
2011-08-18 08:16:05 (24.9 KB/s) - `login.aspx.1' saved [107253/107253]
Saving cookies to abc_cookies.txt.
Done saving cookies.
C:\Temp>wget --referer=http://epaper.abc.com/login.aspx --cookies=on --load-cookies abc_cookies.txt --keep-session-cookies --save-cookies abc_cookies.txt http://epaper.abc.com/PagePrint/16_08_2011_001.pdf --debug
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
DEBUG output created by Wget 1.11.4 on Windows-MinGW.
Stored cookie epaper.abc.com -1 (ANY) / <session> <insecure> [expiry none] ASP.NET_SessionId owcrje55yl45kgmhn43gq145
--2011-08-18 08:16:12-- http://epaper.abc.com/PagePrint/16_08_2011_001.pdf
Resolving epaper.abc.com... seconds 0.00, 999.999.99.99
Caching epaper.abc.com => 999.999.99.99
Connecting to epaper.abc.com|999.999.99.99|:80... seconds 0.00, connected.
Created socket 300.
Releasing 0x00598290 (new refcount 1).
---request begin---
GET /PagePrint/16_08_2011_001.pdf HTTP/1.0
Referer: http://epaper.abc.com/login.aspx
User-Agent: Wget/1.11.4
Accept: */*
Host: epaper.abc.com
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=owcrje55yl45kgmhn43gq145
---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 200 OK
Connection: keep-alive
Date: Thu, 18 Aug 2011 02:46:30 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
content-disposition: attachement; filename=Default_logo.gif
Cache-Control: private
Content-Type: image/GIF
Content-Length: 4568
---response end---
200 OK
Registered socket 300 for persistent reuse.
Length: 4568 (4.5K) [image/GIF]
Saving to: `16_08_2011_001.pdf'
100%[======================================================================================================================>] 4,568 7.74K/s in 0.6s
2011-08-18 08:16:14 (7.74 KB/s) - `16_08_2011_001.pdf' saved [4568/4568]
Saving cookies to abc_cookies.txt.
Done saving cookies.
abc_cookies.txt의 내용
epaper.abc.com FALSE / FALSE 0 ASP.NET_SessionId owcrje55yl45kgmhn43gq145