Вопрос

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?

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top