我用Java和HTML单元解析一个网站。这是我想按的按钮
这是我的一部分代码
public void parse_del(String delno){
try
{
WebClient client = new WebClient(BrowserVersion.CHROME);
client.getOptions().setCssEnabled(false);
client.getOptions().setJavaScriptEnabled(false);
//get first page
HtmlPage currentPage = (HtmlPage)client.getPage("https://www.t-cat.com.tw/Inquire/Trace.aspx");
//find inout area
HtmlTextInput inputbox = (HtmlTextInput) currentPage.getElementById("ContentPlaceHolder1_txtQuery1");
//set value
inputbox.setValueAttribute(delno);
//find the send button
HtmlElement send = (HtmlElement) currentPage.getElementById("ContentPlaceHolder1_btnSend");
//click
HtmlPage newpage = send.click();
}
catch (Exception ex){
System.out.println("ERROR !");
}
}
但是点击按钮后它仍然在同一个页面上。我想原因可能是这句台词
client.getOptions().setJavaScriptEnabled(false);
函数click()无法成功执行,因为我启用了javascript。
但是如果我删除这一行,将会有很多警告信息,比如
17, 2019 10:13:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
Warning: Obsolete content type encountered: 'application/x-javascript'.
17, 2019 10:13:34 com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet isValidCondition
Warning: Unhandled CSS condition type 'PREFIX_ATTRIBUTE_CONDITION'. Accepting it silently.
17, 2019 10:13:34 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
Warning: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: *:x).] sourceName=[https://www.t-cat.com.tw/js/jquery.js] line=[2] lineSource=[null] lineOffset=[0]
17, 2019 10:13:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
Warning: Obsolete content type encountered: 'application/x-javascript'.
17, 2019 10:13:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
Warning: Obsolete content type encountered: 'application/x-javascript'.
17, 2019 10:13:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
Warning: Obsolete content type encountered: 'application/x-javascript'.
整个程序将在开始时存储。
我该怎么做才能解决这个问题?