java 如何使用 JSoup 通过表单提交文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6644168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to submit text via forms using JSoup
提问by Gwindow
I'd like to submit some text into this form using JSoup. How would I go about doing this?
我想使用 JSoup 将一些文本提交到此表单中。我该怎么做呢?
<form id="quickpostform" action="" method="post" style="display: block; text-align: center; ">
<input type="hidden" name="action" value="reply"/>
<input type="hidden" name="auth" value="54a9871a63a1c285879a5327faf3d8d2"/>
<input type="hidden" name="thread" value="135454"/>
<div id="quickreplytext">
<textarea id="quickpost" style="width: 95%; " tabindex="1" onkeyup="resize('quickpost');" name="body" cols="90" rows="8"/>
<br/>
</div>
回答by Jonathan Hedley
Take a look at the jsoup.connectmethod and the Connectioninterface.
看一下jsoup.connect方法和Connection接口。
Once you have the text you want to submit ready to go, you can post it to a URL as a form submission.
准备好要提交的文本后,您可以将其作为表单提交发布到 URL。
E.g.:
例如:
Document doc = Jsoup.connect(url)
.data("action", "reply")
.data("auth", "54a9871a63a1c285879a5327faf3d8d2")
.data("thread", "135454")
.data("quickreplytext", replyText)
.post();
The returned doc
object will be the result page of the post.
返回的doc
对象将是帖子的结果页面。
回答by citizen conn
jSoup
汤
Elements txtArea = doc.select("#quickpost");
txtArea.text(yourText);
jQuery
jQuery
$('#quickpost').val(yourText);