Reputation: 1248
I got this HTML
that i want to parse. I want to submit my own value in an <input>
tag and to submit it and get the next HTML
document.
The template i parse is:
* <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>
My code takes me to a different document but not the one i entered his value for.
MyCode:
// 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());
in the searchedResultDocument i get the same page as before and after the value submit.
What am i doing wrong?
Any suggestions will be very appreciated.
Upvotes: 1
Views: 472
Reputation: 473893
You should make a GET request, not POST:
HtmlPage searchResultDocument = new HtmlPage(formElement.submit().get());
Note that you can visit the search results page directly by navigating to the:
http://search.azlyrics.com/search.php?q=your_search_query
Upvotes: 1