- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码是这样的:
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setTimeout(100000);
HtmlPage page = null;
try {
page = webClient.getPage("http://www.iqiyi.com/a_19rrharlvd.html");
HtmlAnchor ha = page.getFirstByXPath("//a[@data-avlist-page='2']");
page = ha.click();
saveStringToFile("E://abcHtml.txt", page.asXml());
} catch (FailingHttpStatusCodeException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
webClient.closeAllWindows();
我运行这个项目,然后它抛出一些 js 异常,并且 ha.click() 不起作用(我得到的文件与不执行 ha.click() 相同)。像这样的异常(exception):
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "GetLoginJsonInfo" from undefined (http://static.iqiyi.com/js/pingback/qa.js#1)
.....
com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:162)
at java.lang.Thread.run(Unknown Source)
== CALLING JAVASCRIPT ==
function () {
var t = o + "#" + e + "=" + i;
try {
window.JSHandler.logToConsole("xxx");
}
catch (n) {
if (!window.external.GetLoginJsonInfo) {
r.iframeRequest(t);
}
}
}
======= EXCEPTION END ========
现在,我该怎么做才能让它不关心js异常,并运行click函数呢?我尝试其他页面,如果它不抛出异常,则单击功能可以工作。但是当抛出异常时,它将不起作用......--------------------------------------------------------分割线- -------------------------------------------------- 谢谢您的帮助。当我将 htmlUnit 版本更改为 2.25 时,此异常得到解决。但它抛出了一个像这样的新异常:
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: missing ; before statement (http://nlwl.iqiyi.com/apis/urc/getqd?authcookie=null&containsUgc=1&agent_type=1&subTypes=1%2C7%2C9&channelIds=1%2C2&callback=window.Q.__callbacks__.cbd1dmvj#1)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.error(StrictErrorReporter.java:65)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:188)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:167)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:255)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:244)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:237)
at net.sourceforge.htmlunit.corejs.javascript.Parser.autoInsertSemicolon(Parser.java:1089)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1066)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:928)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statements(Parser.java:888)
at net.sourceforge.htmlunit.corejs.javascript.Parser.block(Parser.java:1701)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1032)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:928)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:572)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:492)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2660)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1623)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:184)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1615)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:709)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:879)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:718)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:683)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1069)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:966)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:352)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:239)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:939)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$500(JavaScriptEngine.java:100)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:889)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:824)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:796)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:2454)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventHandler(EventListenersContainer.java:298)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeListeners(EventListenersContainer.java:383)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:107)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeEvent(HtmlScript.java:379)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:354)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:239)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:939)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$500(JavaScriptEngine.java:100)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:889)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:824)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:796)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:2454)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventHandler(EventListenersContainer.java:298)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeListeners(EventListenersContainer.java:383)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:107)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeEvent(HtmlScript.java:379)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:354)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:239)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:939)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$500(JavaScriptEngine.java:100)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:889)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:824)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:796)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:2454)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventHandler(EventListenersContainer.java:298)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeListeners(EventListenersContainer.java:383)
at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:107)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeEvent(HtmlScript.java:379)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:354)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:239)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:939)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$500(JavaScriptEngine.java:100)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:889)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:775)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:751)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:739)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:910)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:307)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:368)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:239)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:258)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:781)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:738)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1243)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1143)
at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:226)
at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:345)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3154)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2117)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:945)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:521)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:472)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:988)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:246)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:188)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:267)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:155)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:517)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:391)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:309)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:456)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:441)
at TestMain.main(TestMain.java:42)
== CALLING JAVASCRIPT ==
{"code":"A00101","come":"no_uid","count":0,"data":{}}
======= EXCEPTION END ========
是不是我忽略了一些条件?可能支持json格式?
最佳答案
已进行快速检查;您的代码在 2.25 版本中运行没有任何问题(只要 saveStringToFile 不执行任何特殊操作)。
关于javascript - HtmlUnit net.sourceforge.htmlunit.corejs.javascript.EcmaError : TypeError: Cannot read property "GetLoginJsonInfo" from undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42712513/
htmlunit 报告从 css 到页面上解析错误的所有内容。 这个怎么静音?? 最佳答案 把这些放在声明 webClient 之后 webClient.setCssError
可能显示 Javascript 测试支持 package htmlunitpoc; import com.gargoylesoftware.htmlunit.WebClient; import co
我正在尝试使用 HtmlUnit 登录到我的本地 wordpress 网站,但它似乎存在 cookie 问题。 那是代码的开头: WebClient webClient = new WebClient
有什么办法可以在 HtmlUnit 中使用 session 更改 url? 我的情况如下所示, 登录 http://test.raja.com与凭据。 获取页面http://home.raja.com
我有以下代码: WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage("http://www.myland.
我研究过htmlunit、httpunit、jwebunit、selenium等ui测试工具。 我对测试工具不是很熟悉。 Htmlunit 在 javascript 支持方面听起来是个不错的选择。然后
我拥有的页面对象是 click() 长链的结果调用(以防万一您想知道如何在不知道用于获取它的 URL 的情况下拥有一个页面对象)。 方法HtmlPage.getDocumentURI未实现。 Html
这是我要抓取的页面:https://www.tokopedia.com/berkahcell2/promo-termurah-vr-virtual-reality-box-v-2-0-remote-b
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我的站点结构看起来像这样: Item 1 Desc 1
我的代码是这样的: WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.setAjaxController(ne
我只希望页面的文本内容,并且希望抓取尽可能轻巧。我可以关闭HTMLUnit开箱即用的所有JavaScript和CSS以及其他外部内容的解析和其他加载功能吗? 最佳答案 我认为与您正在寻找的最接近的东西
我有一个提交按钮,但无法点击.. Send SMS 我已经尝试过这个: page = (HtmlPage) form.getInputByValue("Send SMS").click()
我使用 HtmlUnit 对我的网站进行自动化测试。我的网站使用 gmaps api - 发送外部网站请求需要花费大量时间(我有数百次测试和数千次页面加载)。 我需要一些方法来告诉 HtmlUnit
我使用 HtmlUnit 对我的网站进行自动化测试。我的网站使用 gmaps api - 发送外部网站请求需要花费大量时间(我有数百次测试和数千次页面加载)。 我需要一些方法来告诉 HtmlUnit
我正在使用 HtmlUnit 加载一个充满 JavaScript 的网页。 WebClient 可以很好地执行 JavaScript。 但是,当我单击调用 Ajax 调用的特定表单上的按钮时,即使调用
我正在尝试使用 HtmlUnit 登录 Facebook 页面并查看其 HTML 内容。我正在尝试通过 HtmlUnit 填写登录凭据,但在单击提交按钮时我没有看到正在执行的 session 。 在
Hy...我想使用 HtmlUnit 登录到一些 3rd 方网站。但是 HtmlUnit 应该能够告诉我对输入站点的登录尝试是否成功。有什么办法可以使用 HtmlUnit 执行此任务。请帮忙 ..!!
我正在从 selenium-1 升级到 selenium-2 并尝试新的 HtmlUnit 驱动程序。我已经尝试了一些基本的测试(打开一个页面,get_text,..),它似乎 极慢(我认为 chro
我正在使用 HTMLUnit。我正在访问页面,但是特殊(马耳他)字符显示错误。例如,ġuvni 显示为 ?uvni HtmlPage page = submit_button.click(); Sys
我是一名优秀的程序员,十分优秀!