0

このテキスト領域を、htmlunit を使用してプログラムでプログラムのコードに置き換える必要があります: http://puu.sh/3PLT0.png

package com.cartoonamon;

import java.io.IOException;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class Application {

public static void main(String[] args) {
    new Application();
}

public Application() {
    System.setProperty("socksProxyHost", "localhost");
    System.setProperty("socksProxyPort", "9050");
    final WebClient webClient = new WebClient();
    webClient.getOptions().setJavaScriptEnabled(false);
    webClient.getOptions().setCssEnabled(false);
    HtmlPage page;
    try {
        page = webClient.getPage("http://cartoonamon.com/forum.php");
        HtmlForm login = null;
        for (HtmlForm f : page.getForms()) {
            if (f.getId().equalsIgnoreCase("navbar_loginform")) {
                login = f;
            }
        }
        HtmlTextInput username = login.getElementById("navbar_username");
        HtmlPasswordInput password = login.getElementById("navbar_password");
        HtmlSubmitInput submit = login.getInputByValue("Log in");
        username.setValueAttribute("no looking");
        password.setValueAttribute("no looking");
        HtmlPage page2 = submit.click();
        HtmlPage postThread = webClient.getPage("http://cartoonamon.com/newthread.php?do=newthread&f=26");
        postThread.getFormByName("vbform");
        HtmlTextInput subject = (HtmlTextInput) postThread.getElementById("subject");
        subject.setValueAttribute("test");
        //HtmlTextArea contentBox = (HtmlTextArea)
                System.out.println(postThread.getBody().asText());
        //contentBox.type("test12345678910");
    } catch (FailingHttpStatusCodeException | IOException e) {
        e.printStackTrace();
    }

    webClient.closeAllWindows();
}

}

テキスト領域を取得する方法がわかりませんが、htmlunit を使用して値を変更するだけです! 私のコードの何が問題なのか教えてください!

4

1 に答える 1

0
some example 
1.choose drop down 
// select option ALL
            HtmlSelect select = (HtmlSelect) currentPage.getElementByName("index");
            HtmlOption option = select.getOptionByValue("All");
            select.setSelectedAttribute(option, true);


2.
    // Enter text
            HtmlInput queryInput = currentPage.getElementByName("query");
            queryInput.setValueAttribute(searchValue);
3.
            // click button
            HtmlSubmitInput submitBtn = currentPage.getFirstByXPath("//input[@value='Search']");
            currentPage = submitBtn.click();
于 2013-07-31T06:05:25.213 に答える