Hello,

I want to create a software in Java that submits same/similar data to multiple web forms (eg submit link data to link directories).

What I want to do is, ask the user initially for the data that is to be submitted, and then go to the web form, open it, show only the captcha from that web form on screen, and the end user now has to fill in the captcha. After that, the form is submitted correctly with all data required by it.

Should I manually create the entire data to be sent by that form in code, or should I simply open that form and show only captcha?

Also I prefer latter approach (that I open that form directly) but in this scenario, how do I show only the captcha for user to fill in?

Regards,
Arvind.

Dani AI

Generated

As described, the cleanest options are (A) fetch and fill the form in your Java code, extract the captcha image and show it to the user, then submit the filled form; or (B) load the real page in an embedded browser and hide everything but the captcha so the site JS runs untouched. 's pointer to parsing the <form> is the right starting point; below are practical steps, a short Jsoup-based example, and key pitfalls to watch for.

Core workflow (image-based captchas)

  1. GET the form page and capture response cookies.
  2. Parse the HTML (use Jsoup) to locate the form, collect all inputs (visible + hidden) and the captcha image element and the captcha input name.
  3. Download the captcha image using the same cookies/session and display it in a small Swing/JavaFX UI.
  4. On user input, include that value in the parameter map and POST to the form action, sending the same cookies, referer and headers.
    Small example (illustrative):
Connection.Response page = Jsoup.connect(formUrl).userAgent("Mozilla/5.0").method(Connection.Method.GET).execute();
Document doc = page.parse();
Map<String,String> cookies = page.cookies();

Element form = doc.select("form").first();
Map<String,String> params = new HashMap<>();
for (Element in : form.select("input[name]")) params.put(in.attr("name"), in.attr("value"));

Element capImg = doc.select("img[src~=(?i)captcha]").first();
Connection.Response imgRes = Jsoup.connect(capImg.absUrl("src")).cookies(cookies).ignoreContentType(true).execute();
BufferedImage captcha = ImageIO.read(new ByteArrayInputStream(imgRes.bodyAsBytes()));
// display 'captcha', get 'captchaText'
params.put("captcha_field_name", captchaText);
Connection.Response post = Jsoup.connect(form.absUrl("action")).cookies(cookies).data(params).method(Connection.Method.POST).execute();

Embedded-browser approach
Use JavaFX WebView, SWT Browser, or Selenium (headful/headless Chrome). Let the site run its JS, then inject small DOM/CSS to hide everything but the captcha container. This is usually required for modern JS-driven widgets (Google reCAPTCHA, tokenized captchas) that cannot be extracted as a single image.

Pitfalls and tips
Always include hidden fields (CSRF tokens, __VIEWSTATE), keep the same session cookies, preserve referer and user-agent, and follow redirects. Some captchas are bound to IP/timestamp or are iframe-based (reCAPTCHA) and cannot be separated — show the real widget instead. Respect site terms; automated mass submissions may violate policies or laws. For scale, build per-site profiles (field mappings, captcha selector, headers) rather than trying to auto-fill every site generically.

Recommended Answers

All 3 Replies

Have you looked at how to read an HTML page with a form tag, parse out the parts you need to fill in and how to recognize the captcha image and display it?

Hi

Can you point me to some good resource that shows how to implement the work that you have mentioned (ie. "read an html page with a form tag, parse out the parts you need to fill in ......")?

I am unable to find a good resource for this

Regards,
Arvind.

There are probably sample pieces of code on the forum.
One: send the HTTP GET to read the html from the server
two: Parse HTML to find the <FORM tags

I've no idea how the captcha image is displayed. Perhaps by an <IMG src=

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.