【问题标题】:How to submit a form using Jsoup without the submit button having a name?如何在没有名称的提交按钮的情况下使用 Jsoup 提交表单?
【发布时间】:2015-07-30 03:07:56
【问题描述】:

我有一个要提交的网站表单。问题是该站点的提交按钮没有名称。

表单html:

<form class="login" action="oauth" method="post" name="login">
    <input name="username" value="" id="username"/>
    <input name="password" type="password" id="password"/>
    <input class="button" type="submit" value="Login"/>
</form>

我当前的 Java 代码

Document response = Jsoup.connect(url)
                .data("username", "username")
                .data("password", "reallygoodpassword")
                .data("", "Login") //But how to tag the button here? 
                .post();

或者 Jsoup 无法做到这一点?如果没有,是否有另一种填写表格的方法可以解决这个问题?

【问题讨论】:

  • 你真的需要为那个按钮发布一个值吗?您是否已经尝试过?
  • 如果我只填""或者null,会报错不能为空
  • 按钮不是数据表单的一部分。在 html 中,按钮的“值”属性仅代表按钮标签。您应该将其从您的 post 命令中删除。

标签: java android html forms jsoup


【解决方案1】:

尝试从您喜欢的浏览器提交表单,看看它是如何处理这种情况的。不要忘记在浏览器的开发者工具中显示“网络”选项卡。

一旦您知道浏览器如何处理这种情况,请在您的代码中做同样的事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2011-12-04
    • 2011-04-02
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 2017-08-06
    相关资源
    最近更新 更多