繁体   English   中英

如何在解析html页面时从html页面中的javascript函数中提取变量的值

[英]how to extract a value of variable from a javascript function in the html page while parsing an html page

我必须解析一个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");
            }
        }
    }
};

我会尽力教您顶峰:

//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

希望有帮助=)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM