From: Teo K. L. <teo...@ho...> - 2003-03-19 05:14:36
|
hi All, I m new to HTMLUnit and have a problem. Kindly enlighten me on where i went wrong. cheers, Michael Teo =============================================================== <code> final WebClient webClient = new WebClient(); final URL url = new URL("http://www.google.com.sg"); final HtmlPage page = (HtmlPage)webClient.getPage(url); System.out.println(page.asXml()); </code> =============================================================== <error> *** login *** [DEBUG] HttpConnection - -HttpConnectionManager.getConnection: creating connection for www.google.com.sg:80 via null:-1 using protocol: http:80 [DEBUG] HttpConnection - -HttpConnection.setSoTimeout(0) [DEBUG] HttpMethod - -Execute loop try 1 [DEBUG] HttpMethod - -Adding Host request header [DEBUG] HttpMethod - -Cookie accepted: "$Version=0; PREF=ID=0cefe6a870101aed:LD=en:TM=1048047812:LM=1048047812:S=YxbKBCAOho1qAwC P; $Domain=.google.com.sg; $Path=/" [DEBUG] HttpMethod - -buffering response body [DEBUG] HttpMethod - -Default charset used: ISO-8859-1 ======= EXCEPTION START ======== EcmaError: lineNumber=[2] column=[0] lineSource=[if (!hp.isHomePage('http://www.google.com.sg/')) {document.write("<p><a href=\"/mgyhp.html\" onClick=\"style.behavior='url(#default#homepage)';setHomePage('http://www.go ogle.com.sg/');\">Make Google Your Homepage!</a>");}] name=[ReferenceError] sourceName=[Embedded script] message=["hp" is not defined.] errorObject=[ReferenceError: "hp" is not defined.] com.gargoylesoftware.htmlunit.ScriptException: "hp" is not defined. at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScript Engine.java:199) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(Html Page.java:767) at com.gargoylesoftware.htmlunit.ScriptFilter.executeScript(ScriptFilter.java:1 87) at com.gargoylesoftware.htmlunit.ScriptFilter.endElement(ScriptFilter.java:164) at org.cyberneko.html.HTMLTagBalancer.endElement(Unknown Source) at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(Unknown Source) at org.cyberneko.html.HTMLScanner.scanDocument(Unknown Source) at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source) at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at com.gargoylesoftware.htmlunit.html.HtmlPage.createDocument(HtmlPage.java:249 ) at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:129) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:321) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:241) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:185) at test.Login2.login(Login2.java:37) at test.Login2.jButton1ActionPerformed(Login2.java:164) at test.Login2.access$100(Login2.java:17) at test.Login2$2.actionPerformed(Login2.java:93) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButto n.java:1817) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:4 19) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener .java:245) at java.awt.Component.processMouseEvent(Component.java:5093) at java.awt.Component.processEvent(Component.java:4890) at java.awt.Container.processEvent(Container.java:1566) at java.awt.Component.dispatchEventImpl(Component.java:3598) at java.awt.Container.dispatchEventImpl(Container.java:1623) at java.awt.Component.dispatchEvent(Component.java:3439) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095) at java.awt.Container.dispatchEventImpl(Container.java:1609) at java.awt.Window.dispatchEventImpl(Window.java:1585) at java.awt.Component.dispatchEvent(Component.java:3439) at java.awt.EventQueue.dispatchEvent(EventQueue.java:450) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja va:197) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java :150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136) at java.awt.EventDispatchThread.run(EventDispatchThread.java:99) Enclosed exception: ReferenceError: "hp" is not defined. (Embedded script; line 2) at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597) at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557) at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1076) at org.mozilla.javascript.gen.c5.call(Embedded script:2) at org.mozilla.javascript.gen.c5.exec(Embedded script) at org.mozilla.javascript.Context.evaluateReader(Context.java:820) at org.mozilla.javascript.Context.evaluateString(Context.java:784) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScript Engine.java:191) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(Html Page.java:767) at com.gargoylesoftware.htmlunit.ScriptFilter.executeScript(ScriptFilter.java:1 87) at com.gargoylesoftware.htmlunit.ScriptFilter.endElement(ScriptFilter.java:164) at org.cyberneko.html.HTMLTagBalancer.endElement(Unknown Source) at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(Unknown Source) at org.cyberneko.html.HTMLScanner.scanDocument(Unknown Source) at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source) at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at com.gargoylesoftware.htmlunit.html.HtmlPage.createDocument(HtmlPage.java:249 ) at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:129) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:321) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:241) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:185) at test.Login2.login(Login2.java:37) at test.Login2.jButton1ActionPerformed(Login2.java:164) at test.Login2.access$100(Login2.java:17) at test.Login2$2.actionPerformed(Login2.java:93) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButto n.java:1817) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:4 19) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener .java:245) at java.awt.Component.processMouseEvent(Component.java:5093) at java.awt.Component.processEvent(Component.java:4890) at java.awt.Container.processEvent(Container.java:1566) at java.awt.Component.dispatchEventImpl(Component.java:3598) at java.awt.Container.dispatchEventImpl(Container.java:1623) at java.awt.Component.dispatchEvent(Component.java:3439) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095) at java.awt.Container.dispatchEventImpl(Container.java:1609) at java.awt.Window.dispatchEventImpl(Window.java:1585) at java.awt.Component.dispatchEvent(Component.java:3439) at java.awt.EventQueue.dispatchEvent(EventQueue.java:450) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja va:197) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java :150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136) at java.awt.EventDispatchThread.run(EventDispatchThread.java:99) == CALLING JAVASCRIPT == //<!-- if (!hp.isHomePage('http://www.google.com.sg/')) {document.write("<p><a href=\"/mgyhp.html\" onClick=\"style.behavior='url(#default#homepage)';setHomePage('http://www.go ogle.com.sg/');\">Make Google Your Homepage!</a>");} //--> ======= EXCEPTION END ======== </error> |
From: Mike B. <mb...@Ga...> - 2003-03-19 11:15:41
|
Teo Kian Lee wrote: > I m new to HTMLUnit and have a problem. Kindly enlighten me on where i went > wrong. First of all, be aware that googles usage policy specifically prohibits using a bot to access their content. By using HtmlUnit to access google, you are violating their usage agreement. HtmlUnit 1.2 has a problem with external javascript files that are referenced from within the body which is most likely the problem you are seeing. This bug has already been fixed in cvs - if you want to try building a new jar from cvs then refer to http://htmlunit.sourceforge.net/buildingFromCvs.html I'll be packaging up a 1.2.1 release fairly soon. There seem to have been a number of bugs reported yesterday and I haven't had a chance to go through them all to see which ones are critical and should go into 1.2.1 -- Mike Bowler Principal, Gargoyle Software Inc. Voice: (416) 822-0973 | Email : mb...@Ga... Fax : (416) 822-0975 | Website: http://www.GargoyleSoftware.com |