1

HTMLページを解析する必要があります。javascript 関数に割り当てられている以下の html の name 要素の値を抽出する必要があります。JSoup を使用して行うにはどうすればよいですか。

<input type="hidden" name="fields.DEPTID.value"/>

JS:

departmentId.onChange = function(value) {                                       
    var departmentId = dijit.byId("departmentId");

    if (value == null || value == "") {
        document.transferForm.elements["fields.DEPTID.value"].value = "";
        document.transferForm.elements["fields.DEPTID_DESC.value"].value = "";
    } else {
        document.transferForm.elements["fields.DEPTID.value"].value = value;
        document.transferForm.elements["fields.DEPTID_DESC.value"].value = departmentId.getDisplayedValue();

        var locationID = departmentId.store.getValue(departmentId.item, "loctID");
        var locationDesc = departmentId.store.getValue(departmentId.item, "loct");

        locationComboBox = dijit.byId("locationId");

        if (locationComboBox != null) {
            if (locationID != "") {
                setLocationComboBox(locationID, locationDesc);
            } else {
                setLocationComboBox("AMFL", "AMFL - AMY FLORIDA");
            }
        }
    }
};
4

1 に答える 1

0

私はトップからあなたに教えようとします:

//Connect to the url, and get its source html
Document doc = Jsoup.connect("url").get();

//Get ALL the elements in the page that meet the query
//you passed as parameter. 
//I'm querying for all the script tags that have the
//name attribute inside it
Elements elems = doc.select("script[name]");

//That Elements variable is a collection of
//Element. So now, you'll loop through it, and
//get all the stuff you're looking for
for (Element elem : elems) {
    String name = elem.attr("name");

    //Now you have the name attribute
    //Use it to whatever you need.
}

Jsoup クエリを使用して他の要素を取得したい場合は、次の API ドキュメントを参照してください: Jsoup セレクター API

お役に立てば幸いです=)

于 2012-07-24T20:58:19.057 に答える