Bu siteye erişmesi gereken küçük bir bot yazmaya çalışıyorum http://lsa.colorado.edu/cgi-bin/LSA-pairwise.html, metinde bir metin girin textarea ve gönderilen sayfayı gönder düğmesine basarak gönderilmesini sağlayın. Bu bir dilbilim projesi için.HtmlUnit HtmlSubmitInput.click() "Unknown URL" olarak düzeltilen "Yanlış URL" ile sonuçlanan bir UnknownHostException adresine yönlendirir
Apr 10, 2016 2:38:35 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNUNG: Incorrect URL "http:/cgi-bin/LSA-pairwise-x.html" has been corrected
URL sonra
Bu
http://lsa.colorado.edu/cgi-bin/LSA-pairwise-x.html
olmalıdır: Ben HtmlSubmitInput düğmesini tıklatın yürütmek zaman IncorrectnessListenerImpl beni bildirir olarak Ancak iade URL bozuk olmasına görünüyor Aşağıdaki stacktrace (uzunluk nedeniyle kısaltılmış) yol açar:Exception in thread "main" java.lang.RuntimeException: java.net.UnknownHostException: cgi-bin: unknown error at com.gargoylesoftware.htmlunit.WebClient.download(WebClient.java:2078) at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:141) at com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickStateUpdate(HtmlSubmitInput.java:90) at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:795) at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:742) at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:689) at LSABot.submitInput(LSABot.java:30) at Start.main(Start.java:8) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) [...]
Benim tahminim, HtmlUnit'in URL'yi düzeltmeye çalışmasıdır, ancak bu sonuçta sadece "cgi-bin" ile sonuçlanır. Tekrar tekrar araştırdım, ancak sorunumla alakalı bir şey bulamadım.
Benim LSABot sınıfı:
public class LSABot { final WebClient webClient; private HtmlPage mainPg, rsltPg; private HtmlForm htmlForm; private HtmlTextArea txtA; private HtmlSubmitInput submitBt; public LSABot() throws Exception { this.webClient = new WebClient(BrowserVersion.CHROME); this.webClient.getOptions().setJavaScriptEnabled(true); this.mainPg = this.webClient.getPage("http://lsa.colorado.edu/cgi-bin/LSA-pairwise.html"); this.htmlForm = this.mainPg.getForms().get(0); this.txtA = this.htmlForm.getTextAreaByName("txt1"); this.submitBt = this.htmlForm.getInputByValue("Submit Texts"); } public void submitInput(String input) { this.txtA.setText(input); try { this.rsltPg = this.submitBt.click(); this.webClient.waitForBackgroundJavaScript(30*1000); } catch (IOException ioe) { ioe.printStackTrace(); } }
Parlak. Teşekkür ederim! HtmlForm.setAttribute() yöntemi tam olarak ihtiyacım olan şeydi! –