How to submit text via forms using JSoup

15,449

Solution 1

Take a look at the jsoup.connect method and the Connection interface.

Once you have the text you want to submit ready to go, you can post it to a URL as a form submission.

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.

Solution 2

jSoup

Elements txtArea = doc.select("#quickpost");
txtArea.text(yourText);

JSoup Documentation

jQuery

$('#quickpost').val(yourText);
Share:
15,449
Gwindow
Author by

Gwindow

Updated on June 25, 2022

Comments

  • Gwindow
    Gwindow about 2 years

    I'd like to submit some text into this form using JSoup. How would I go about doing this?

    <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>
    
  • Gwindow
    Gwindow almost 13 years
    How would I go about posting it back to the site?
  • citizen conn
    citizen conn almost 13 years
    jSoup is for scraping and parsing HTML, not really for modifying display. For that you would use jQuery on the client side. See my edited answer.
  • Gwindow
    Gwindow almost 13 years
    anyway to do it with jSoup rather than jQuery?
  • Gwindow
    Gwindow almost 13 years
    I'm not sure how to answer that question.
  • citizen conn
    citizen conn almost 13 years
    What are you using to show web pages to the user? Java is a server-side technology.
  • Gwindow
    Gwindow almost 13 years
    I'm writing an android app, I'm parsing page sources from a site using JSoup, and displaying certain parts.