Package

Source Code of Ex_htmlunit


import java.util.List;
import java.util.Set;

import org.apache.commons.httpclient.Cookie;

import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.ScriptException;
import com.gargoylesoftware.htmlunit.WebClient; 
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm; 
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlOption;
import com.gargoylesoftware.htmlunit.html.HtmlPage; 
import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; 
import com.gargoylesoftware.htmlunit.html.HtmlTextInput; 
  
public class Ex_htmlunit
   private String queryUrl = "http://ged.capes.gov.br/AgProd/silverstream/pages/pgRelBolsistasProdPesq.html";
   private String resultUrl = "http://ged.capes.gov.br/AgProd/silverstream/pages/pgRelBolsistasProdPesqResultado.html";
  
  
  public void search () throws Exception
   WebClient wb = new WebClient ()
   System.out.println("Aqui2");
   HtmlPage queryPage = (HtmlPage) wb.getPage(queryUrl)
   System.out.println("Aqui0");
   //Estado
   HtmlForm form = queryPage.getFormByName("AG");
   HtmlSelect Select = form.getSelectByName("S7_");
   Select.setSelectedAttribute("6", true);
   List<HtmlOption> list = Select.getOptions();
   /*for(HtmlOption ho: list){
     System.out.println(ho.asText());
   }
   System.out.println(queryPage.asText());
   */
   System.out.println("Aqui1");
   //IEF
   queryPage = (HtmlPage) wb.getPage(queryUrl);
   form = queryPage.getFormByName("AG");
   Select = form.getSelectByName("S9_");
   Select.setSelectedAttribute("1", true);
   list = Select.getOptions();
   /*for(HtmlOption ho: list){
     System.out.println(ho.asText());
   }
   System.out.println(queryPage.asText());
   */
  
   //Area
   queryPage = (HtmlPage) wb.getPage(queryUrl);
   form = queryPage.getFormByName("AG");
   Select = form.getSelectByName("S11_");
   Select.setSelectedAttribute("10", true);
   list = Select.getOptions();
   /*for(HtmlOption ho: list){
     System.out.println(ho.asText());
   }
   System.out.println(queryPage.asText());
   */
  
//Programa
   queryPage = (HtmlPage) wb.getPage(queryUrl);
   form = queryPage.getFormByName("AG");
   Select = form.getSelectByName("S13_");
   Select.setSelectedAttribute("1", true);
   list = Select.getOptions();
   /*for(HtmlOption ho: list){
     System.out.println(ho.asText());
   }*/
   System.out.println(queryPage.asText());
  
   /* 
   //Professores
   List<HtmlRadioButtonInput> radioButtonList = form.getRadioButtonsByName("S15_");
   for(HtmlRadioButtonInput hr: radioButtonList){
     System.out.println(hr);
   }
   */
   HtmlInput hi= form.getInputByName("S19_");
   System.out.println(hi);
   Set<Cookie> cookies = wb.getCookieManager().getCookies();
   try{
  
   }
   catch(ScriptException e){}
   //hi.click();
   /*Page p=hi.setChecked(true);
   //queryPage=wb.getPage(queryUrl);
   System.out.println(p.getWebResponse().getContentAsString());
  
   //Set<Cookie> cookies = wb.getCookieManager().getCookies();
   String strCookie = "";
  
   for(Cookie c : cookies){
     strCookie +=c.getName()+"="+c.getValue()+";";
   }
  
   WebClient wb1= new WebClient();
   CookieManager cm = wb.getCookieManager();
   wb1.setCookieManager(cm);
  
   HtmlPage rPage = wb1.getPage(resultUrl);
   System.out.println(rPage.asText());
   */
 
  
  public static void main (String args[]) throws Exception
   Ex_htmlunit TG = new Ex_htmlunit()
   TG.search ()
 
TOP

Related Classes of Ex_htmlunit

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.