Make HtmlUnit not output warnings to stdout

View: New views
5 Messages — Rating Filter:   Alert me  

Make HtmlUnit not output warnings to stdout

by Kent Larsson-3 :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

I'm using HtmlUnit from Groovy for some screen scraping duty (I want
to be able to query my local bus company for information from the
command line), but I get some warnings:

$ ./gt.groovy
Mar 18, 2009 6:46:42 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or
'application/ecmascript' for remotely loaded JavaScript element at
'http://www.vl.se/util/javascript/system.js', but got
'application/x-javascript'.
Mar 18, 2009 6:46:42 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or
'application/ecmascript' for remotely loaded JavaScript element at
'http://www.vl.se/template/js/js_functions.js', but got
'application/x-javascript'.
Mar 18, 2009 6:46:43 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or
'application/ecmascript' for remotely loaded JavaScript element at
'https://ssl.webserviceaward.com/wsc/client/wscSelVisit901198.shtml',
but got 'text/html'.
Mar 18, 2009 6:46:43 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Start Västmanlands lokaltrafik | Västmanlands lokaltrafik

The script contents are:

#!/usr/bin/env groovy
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.WebClient;

final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://www.vl.se");
println(page.getTitleText())

As you can see I'm not doing anything fancy. :-) Does the warnings
mean I won't be able to utilize HtmlUnit to navigate the page? And if
that is not the case, is it possible to turn the warnings off by any
means?

Best regards,
Kent

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Re: Make HtmlUnit not output warnings to stdout

by gredler :: Rate this Message:

| View Threaded | Show Only this Message

Hi Kent,

You can either customize the logging configuration to ignore warnings, or you can configure your WebClient to use a custom incorrectness listener that ignores all callbacks.

And no, warnings are not errors -- you can just forget about them and ignore them, if you want. These specific warnings don't really make sense in the context of web scraping, but are important when HtmlUnit is used for testing purposes.

Take care,

Daniel


On Wed, Mar 18, 2009 at 1:50 PM, Kent Larsson <kent.larsson@...> wrote:
Hi,

I'm using HtmlUnit from Groovy for some screen scraping duty (I want
to be able to query my local bus company for information from the
command line), but I get some warnings:

$ ./gt.groovy
Mar 18, 2009 6:46:42 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or
'application/ecmascript' for remotely loaded JavaScript element at
'http://www.vl.se/util/javascript/system.js', but got
'application/x-javascript'.
Mar 18, 2009 6:46:42 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or
'application/ecmascript' for remotely loaded JavaScript element at
'http://www.vl.se/template/js/js_functions.js', but got
'application/x-javascript'.
Mar 18, 2009 6:46:43 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or
'application/ecmascript' for remotely loaded JavaScript element at
'https://ssl.webserviceaward.com/wsc/client/wscSelVisit901198.shtml',
but got 'text/html'.
Mar 18, 2009 6:46:43 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Start Västmanlands lokaltrafik | Västmanlands lokaltrafik

The script contents are:

#!/usr/bin/env groovy
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.WebClient;

final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://www.vl.se");
println(page.getTitleText())

As you can see I'm not doing anything fancy. :-) Does the warnings
mean I won't be able to utilize HtmlUnit to navigate the page? And if
that is not the case, is it possible to turn the warnings off by any
means?

Best regards,
Kent

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user



--
Daniel Gredler
http://daniel.gredler.net/

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Re: Make HtmlUnit not output warnings to stdout

by DOUTCH GARETH-GDO003 :: Rate this Message:

| View Threaded | Show Only this Message

Kent,

If you are using a logger, you can silence the message by ensuring you don't use the rootLogger. If not then you can use something like the following to silence it:

#This is Jython code, you can use something similar.
from java.util import logging
from org.apache.commons.logging import LogFactory
logger = LogFactory.getLog('com.gargoylesoftware.htmlunit')
logger.getLogger().setLevel(logging.Level.OFF)

Cheers,

Gareth
 

-----Original Message-----
From: Kent Larsson [mailto:kent.larsson@...]
Sent: 18 March 2009 17:51
To: htmlunit-user@...
Subject: [Htmlunit-user] Make HtmlUnit not output warnings to stdout
en
Hi,

I'm using HtmlUnit from Groovy for some screen scraping duty (I want to be able to query my local bus company for information from the command line), but I get some warnings:

$ ./gt.groovy
Mar 18, 2009 6:46:42 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://www.vl.se/util/javascript/system.js', but got 'application/x-javascript'.
Mar 18, 2009 6:46:42 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://www.vl.se/template/js/js_functions.js', but got 'application/x-javascript'.
Mar 18, 2009 6:46:43 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://ssl.webserviceaward.com/wsc/client/wscSelVisit901198.shtml',
but got 'text/html'.
Mar 18, 2009 6:46:43 PM
com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Start Västmanlands lokaltrafik | Västmanlands lokaltrafik

The script contents are:

#!/usr/bin/env groovy
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.WebClient;

final WebClient webClient = new WebClient(); final HtmlPage page = webClient.getPage("http://www.vl.se");
println(page.getTitleText())

As you can see I'm not doing anything fancy. :-) Does the warnings mean I won't be able to utilize HtmlUnit to navigate the page? And if that is not the case, is it possible to turn the warnings off by any means?

Best regards,
Kent

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are powering Web 2.0 with engaging, cross-platform capabilities. Quickly and easily build your RIAs with Flex Builder, the Eclipse(TM)based development software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com _______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Re: Make HtmlUnit not output warnings to stdout

by avisual :: Rate this Message:

| View Threaded | Show Only this Message

implement a IncorrectnessListener

<code>
import com.gargoylesoftware.htmlunit.IncorrectnessListener;

public class MyIncorrectnessListener implements IncorrectnessListener
{

  @Override
  public void notify(String arg0, Object arg1)
  {
    //System.err.println("Argument : " + arg0.toString() + ", Object : ");
  }

}
</code>

you can do the same for error handler

then in your test

<code>
 final IncorrectnessListener il = new MyIncorrectnessListener();
  final MyErrorHandler eh = new MyErrorHandler();
  webClient.setIncorrectnessListener(il);
      webClient.setJavaScriptEnabled(true);
      webClient.setCssErrorHandler(eh);

</code>

Does this help

Re: Make HtmlUnit not output warnings to stdout

by Ahmed Ashour :: Rate this Message:

| View Threaded | Show Only this Message

* Resending, you must subscribe to the list before posting ...


avisual wrote:
implement a IncorrectnessListener

<code>
import com.gargoylesoftware.htmlunit.IncorrectnessListener;

public class MyIncorrectnessListener implements IncorrectnessListener
{

  @Override
  public void notify(String arg0, Object arg1)
  {
    //System.err.println("Argument : " + arg0.toString() + ", Object : ");
  }

}
</code>

you can do the same for error handler

then in your test

<code>
 final IncorrectnessListener il = new MyIncorrectnessListener();
  final MyErrorHandler eh = new MyErrorHandler();
  webClient.setIncorrectnessListener(il);
      webClient.setJavaScriptEnabled(true);
      webClient.setCssErrorHandler(eh);

</code>

Does this help