| Newsgroups |
gmane.comp.web.httpunit.devel |
| Message-ID |
<[email protected]> |
I'm using httpunit to scrape links for a site that requires login and then
download files from those links. I'm close to getting it to work, but not
quite. I login, then get to the next page (which can be accessed only by
logging in), then get the links. But I can't download the files. I think
the issue is that it is not a "direct" download but rater a function
called "GetDoc.do" is called for the download.
The page requested here:
request = new
GetMethodWebRequest("http://www.ctslink.com/FullDocument.do?Selector=SeriesDocument%2CIMPORTDATA%2CMBS%2CAMIT%2CNONE%2CAMIT_COL%2CZIP%2C200707");
A link to download a file looks like this:
https://www.ctslink.com/GetDoc.do?Selector=SeriesDocument,IMPORTDATA,MBS,AMIT,NONE,AMIT_COL,ZIP,200701
(this specifies a zip file for January, 2007)
A response from a request for one of these looks like:
response from request = HttpWebResponse
[url=http://www.ctslink.com/GetDoc.do?Selector=SeriesDocument%2CIMPORTDATA%2CMBS%2CAMIT%2CNONE%2CAMIT_COL%2CZIP%2C200706;
headers=
CONTENT-DISPOSITION: inline; filename=AMIT_COL.zip
CONTENT-TYPE: application/zip
CONNECTION: close
CACHE-CONTROL: max-age=30, private
EXPIRES: Thu, 01 Jan 1970 00:00:30 GMT
SERVER: Netscape-Enterprise/6.0
DATE: Fri, 24 Aug 2007 19:19:04 GMT ]
The url shown in the response from click is page containing the buttons,
that was requested with the above statement.
No file is downloaded, though.
Any ideas how to do this?
--------------------------------------------------------------------------
try {
// create the conversation object which will maintain state for us
WebConversation wc = new WebConversation();
// Obtain the page
WebRequest request = new
GetMethodWebRequest("https://www.ctslink.com/login.do");
WebResponse response = wc.getResponse(request);
// get sign on form
WebForm webForm[] = response.getForms();
// sign-on form is 3rd form on the page
WebForm signOnForm = webForm[2];
// sign on
signOnForm.setParameter("userid", CTSLINK_USER_NAME);
signOnForm.setParameter("password", CTSLINK_PASSWORD);
response = signOnForm.submit();
// Obtain next page
request = new GetMethodWebRequest(
"http://www.ctslink.com/FullDocument.do?Selector=SeriesDocument%2CIMPORTDATA%2CMBS%2CAMIT%2CNONE%2CAMIT_COL%2CZIP%2C200707");
response = wc.getResponse(request);
// get all links on this page
WebLink[] webLinkArray = response.getLinks();
// loop through webLinkArray, looking for pdfs
Vector<String> urlStringVector = new Vector();
for (WebLink webLink : webLinkArray) {
String urlString = webLink.getURLString();
// if string contains the right stuff (to get a doc)
if (urlString.contains("/GetDoc.do?Selector=SeriesDocument")) {
request = webLink.getRequest();
response = wc.getResponse(request);
System.out.println("response from request = " + response);
}
}
} catch (Exception e) {
System.err.println("Exception: " + e);
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/