我正在使用https://www.base64decode.org/使用java中的htmlunit解码编码文本。
这是网站的HTML代码
<form name="convert_text" method="post" action="/">
<textarea name="input" placeholder="Type (or paste) here..."></textarea>
<button type="submit" name="decode" value="decode"><i class="fa fa-chevron-left"></i>DECODE<i class="fa fa-chevron-right"></i></button>
<select name="charset"><option value="UTF-8">UTF-8</option><option value="ASCII">ASCII</option><option value="CP1256">CP1256</option><option value="ISO-8859-1">ISO-8859-1</option><option value="ISO-8859-2">ISO-8859-2</option><option value="ISO-8859-6">ISO-8859-6</option><option value="ISO-8859-15">ISO-8859-15</option><option value="Windows-1252">Windows-1252</option></select>
<span>You may also select input charset.</span>
<div class="clear"></div>
</form>
<textarea name="output" placeholder="Result goes here..."></textarea>
这是我的Decode.java代码
public class Decode {
public static void de(String str){
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setJavaScriptEnabled(false);
try{
HtmlPage page = webClient.getPage("https://www.base64decode.org/");
HtmlForm form = page.getFormByName("convert_text");
HtmlTextArea content = form.getTextAreaByName("input");
content.setText(str);
HtmlElement button = form.getButtonByName("decode");
button.click();
HtmlTextArea contentArea = form.getTextAreaByName("output"); //can't use Htmlform, as textarea is outside form element
String st = contentArea.getText();
System.out.println(st);
}
catch(Exception e){System.out.print(e);}
}
}
如何在第二个textarea中设置文本(它是外部表单元素)?
答案 0 :(得分:1)
这里有一个有效的例子:
希望有所帮助。
mousearea