Java 通过直接更改formData keyVals的列表jsoup来更改FormElement的信息

Java 通过直接更改formData keyVals的列表jsoup来更改FormElement的信息,java,forms,dom,web-scraping,jsoup,Java,Forms,Dom,Web Scraping,Jsoup,我正在尝试使用Jsoup库的类FormElement填写表单。我的问题是,它不会更改它提交的KeyVals中的值。我在Jsoup文档中发现,他们是故意这样做的: public List<Connection.KeyVal> formData() Get the data that this form submits. The returned list is a copy of the data, and changes to the contents of the list wil

我正在尝试使用Jsoup库的类FormElement填写表单。我的问题是,它不会更改它提交的KeyVals中的值。我在Jsoup文档中发现,他们是故意这样做的:

public List<Connection.KeyVal> formData()
Get the data that this form submits. The returned list is a copy of the data, and changes to the contents of the list will not be reflected in the DOM.
Returns:
a list of key vals
请注意,我知道我可以通过更改DOM中每个元素的值来实现这一点。然而,我不认为这种方式既不干净也不是最快的。那么有没有办法通过直接更改表单数据中的值来实现这一点呢?

每次调用该方法都会通过遍历DOM并拉出值来创建一个新的结果列表。所以,不要继续重新评估这种方法。取而代之的是,获取一个引用并从中设置值。例如:

FormElement form = (FormElement) document.select(form#formulaire).first();
List<Connection.KeyVal> formData = form.formData();
System.out.println(formData.get(4).value()); //printing the value of  KeyVal #4 
form.formData().get(4).value("value changed");//changing its value
System.out.println(form.formData().get(4).value());//printing again its value which must be different

Result: 
Old value
value changed
然后可以将相同的表单数据传递到新的post/get请求中

我确实希望人们只是更新DOM。这是非常有效的,在formdata对象中更改某些内容的值与在DOM中更改其值的效率没有什么不同,它们都由相同类型的哈希/数组支持。而且没有HTML解析或其他任何东西

每次调用该方法都会通过遍历DOM并提取值来创建一个新的结果列表。所以,不要继续重新评估这种方法。取而代之的是,获取一个引用并从中设置值。例如:

FormElement form = (FormElement) document.select(form#formulaire).first();
List<Connection.KeyVal> formData = form.formData();
System.out.println(formData.get(4).value()); //printing the value of  KeyVal #4 
form.formData().get(4).value("value changed");//changing its value
System.out.println(form.formData().get(4).value());//printing again its value which must be different

Result: 
Old value
value changed
然后可以将相同的表单数据传递到新的post/get请求中

我确实希望人们只是更新DOM。这是非常有效的,在formdata对象中更改某些内容的值与在DOM中更改其值的效率没有什么不同,它们都由相同类型的哈希/数组支持。而且没有HTML解析或其他任何东西