Reputation: 105
I have an html file that has this part:
<td> <a href="/romarin/detail.do?ID=0"> NAME </a> </td>
How can I open this link on href
with HtmlUnit?
My code:
final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_11);
final HtmlPage page1 = webClient.getPage("file:\\" + newrfile);
final HtmlSubmitInput button = form.getInputByName("submit");
final HtmlPage page2 = button.click();
System.out.println(page2.asText());
final HtmlForm form2 = page2.getFormByName("SearchForm");
Upvotes: 5
Views: 8939
Reputation: 5549
You can use getAnchorByHref:
HtmlAnchor htmlAnchor = page2.getAnchorByHref("/romarin/detail.do?ID=0");
Then you can click:
HtmlPage page3 = anchor.click();
Then you can save the page as a file:
page3.saveAs(some_file);
Or
System.out.println(page3.asXml());
Upvotes: 10