gpt4 book ai didi

javascript - ReferenceError: "validate"未定义。在尝试使用 HTMLUnit 提交表单时

转载 作者:行者123 更新时间:2023-11-29 23:38:27 24 4
gpt4 key购买 nike

我想提交表格到this带有 HTMLUnit 的网站,但我收到标题错误。

这是我的代码:

try (final WebClient webClient = new WebClient(BrowserVersion.CHROME, "127.0.0.1", 57703)) {
//webClient.getOptions().setThrowExceptionOnScriptError(false);
final HtmlPage page1 = webClient.getPage("http://tagmp3.net/");
final HtmlDivision div = (HtmlDivision) page1.getElementById("urlForm");
final DomNodeList<DomElement> forms = page1.getElementsByTagName("form");
final HtmlForm form = (HtmlForm) forms.get(0);
final HtmlTextInput textField = form.getInputByName("filepath");
final HtmlSubmitInput button = form.getInputByName("button");
textField.setValueAttribute(url);
final HtmlPage page2 = button.click();
System.out.println(page2.getBaseURL());
}

这是我得到的错误:

EcmaError: lineNumber=[4] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[http://code.jquery.com/jquery-3.1.1.min.js] message=[TypeError: Cannot set property "innerHTML" of undefined to "<form></form><form></form>" (http://code.jquery.com/jquery-3.1.1.min.js#4)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "innerHTML" of undefined to "<form></form><form></form>" (http://code.jquery.com/jquery-3.1.1.min.js#4)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:894)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:637)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:518)
blah blah blah....

我试图关闭脚本错误,但没有成功。

顺便说一句,我在网站的 HTML 中找到了这个:

<form onsubmit="return validate(this)" method="post" action="index.php">

我怎样才能解决这个问题?

最佳答案

在顶部添加这一行:

webClient.getOptions().setJavaScriptEnabled(false);

关于javascript - ReferenceError: "validate"未定义。在尝试使用 HTMLUnit 提交表单时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45843026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com