protected WebResponse getCurrentPage() { return root.wc.getCurrentPage(); }
/** * Finds a hyper-link that has the specified text and whose * target URL starts with the given prefix. */ static WebLink findLink( WebConversation wc, String text, String urlPrefix ) throws ProcessingException, SAXException { WebLink[] links = wc.getCurrentPage().getLinks(); for( int i=0; i<links.length; i++ ) { if( links[i].asText().indexOf(text)==-1 ) continue; if( !links[i].getURLString().startsWith(urlPrefix)) continue; return links[i]; } throw new ProcessingException("no link found for '"+text+'\''); }
WebResponse resp = wc.getCurrentPage(); String fileName = resp.getURL().getFile(); fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
protected Object scrape() throws IOException, SAXException, ProcessingException { WebResponse r = wc.getResponse("https://www.dev.java.net/servlets/TLogin"); WebForm form = r.getFormWithID("loginform"); form.setParameter("loginID",userName); form.setParameter("password",password); checkError(form.submit(form.getSubmitButton("Login"))); // check if the login was successful if( wc.getCurrentPage().getURL().toExternalForm().indexOf("TLogin")!=-1) throw new ProcessingException("authentication failed. invalid username/password"); // create a special myself object. myself = new JNMyself(JavaNet.this,userName); users.put(userName,myself); return null; } }.run();