【发布时间】:2016-06-28 14:48:36
【问题描述】:
我得到了这个网站http://findmusicbylyrics.com/,它使用<form> 和<input> 标签来输入和提交搜索。
相关 HTML:
<form action="/search.php" id="cse-search-box">
<div>
<input type="hidden" name="cx" value="partner-pub-1936238606905173:1893984547" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="search" name="q" id="main_search_box" autofocus="autofocus" />
<input type="submit" name="sa" value="Search" id="main_search_button" />
</div>
</form>
我想用Jsoup进入我的String,应用搜索并得到HTML的搜索页面。
我的代码:
try {
HtmlPage htmlPage = new HtmlPage(Jsoup.connect("http://findmusicbylyrics.com/").get()); // Connect to the HTML page
Element formElement = htmlPage.getElement("form#cse-search-box"); // <form action="/search.php" id="cse-search-box"> tag
Element searchBoxElement = formElement.select("input#main_search_box").first(); // <input type="search" name="q" id="main_search_box" autofocus="autofocus" /> tag
Element searchBoxElement2 = searchBoxElement.attr("input", "Love");
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
如果我离开这里,我如何离开这里,因为我不知道Jsoup 是否可以处理这种事情。
【问题讨论】:
标签: java html forms input jsoup