Jsoup formElement.submit().post() 未提交指定的值

Jsoup formElement.submit().post() not submimting the value specified

我得到了这个 HTML 我想解析。我想在 <input> 标签中提交我自己的值并提交它并获取下一个 HTML 文档。

我解析的模板是:

     *  <div class="collapse navbar-collapse" id="search-collapse">
     *
     *      <form class="navbar-form navbar-right search" method="get" action="http://search.azlyrics.com/search.php" role="search">
     *          <div class="input-group">  
     *      <input type="text" class="form-control" placeholder="" name="q" id="q">
     *          <span class="input-group-btn">
     *              <button class="btn btn-primary" type="submit"><span class="glyphicon glyphicon-search"></span> Search</button>
     *          </span>
     *          </div>   
     *      </form>
     *
     *  </div>

我的代码将我带到一个 不同的 文档,但不是我为其输入值的文档。

我的代码:

    // Get to <form class="navbar-form navbar-right search" method="get" action="http://search.azlyrics.com/search.php" role="search">
    FormElement formElement = htmlPage.getHtmlDocument().select("form.navbar-form.navbar-right.search").forms().get(0);

    // Set my searched lyrics in the <input type="text" class="form-control" placeholder="" name="q" id="q">
    formElement.select("input[name=q]").val(searchedLyrics);

    // Get the HTML document after my searched lyrics applied
    HtmlPage searchResultDocument = new HtmlPage(formElement.submit().post());

    System.out.println(searchResultDocument.getHtmlDocument().text());

在 searchedResultDocument 中,我得到与值提交前后相同的页面。

我做错了什么?

如有任何建议,我们将不胜感激。

您应该发出 GET 请求,而不是 POST:

HtmlPage searchResultDocument = new HtmlPage(formElement.submit().get());

请注意,您可以直接访问搜索结果页面,方法是导航至:

http://search.azlyrics.com/search.php?q=your_search_query