Frage

For doing web scraping I'm trying to figure out when I get a specific url if the loging form is present:

  if(!page.getForms().isEmpty()){
     HtmlForm loginForm = page.getFormByName("Valid");
     if(loginForm != null){
      //No valid session so login
       loginForm.getInputByName("usercode").setValueAttribute("MyUser"); 
       loginForm.getInputByName("userpwd").setValueAttribute("mypwd");

But this doesn't work because I got an exception when the form is not present. Is there a way of detecting without exception the presence of the form?

War es hilfreich?

Lösung

Further to the comments. I close the question and stop looking for strange things to do in place of of catching the exception.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top