I am trying to make java app using htmlunit to get info from site. So the thing is I have to fill the textbox with my url and click on anchor to submit form. The first part works great (finding form and filling form textbox with my data), but I can't find the anchor using getByXPath() method, the anchor does not have name or value.
Here is my code:
public class JobolizerCrawler {
private final String jobolizerUrl = "";
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
public JobolizerCrawler () {
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(false);
}
public void fillTextBoxWithUrl(String vacancyURL) throws IOException {
final HtmlPage page = webClient.getPage(jobolizerUrl);
System.out.println(page.asText());
final HtmlForm form = page.getFirstByXPath("//form[@action='/phpProxy/getJOBolizerResponse_en.php']");
final HtmlTextInput input = form.getInputByName("url");
input.setText(vacancyURL);
HtmlButton button = (HtmlButton) page.getByXPath("/form[@action='/phpProxy/getJOBolizerResponse_en.php']/a[@id=lightboxlink]").get(0);
HtmlPage page2 = button.click();
String page2Text = page2.asText();
System.out.println(page2Text);
}
}
I am trying to make java app using htmlunit to get info from http://www.jobolizer. site. So the thing is I have to fill the textbox with my url and click on anchor to submit form. The first part works great (finding form and filling form textbox with my data), but I can't find the anchor using getByXPath() method, the anchor does not have name or value.
Here is my code:
public class JobolizerCrawler {
private final String jobolizerUrl = "http://www.jobolizer.";
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
public JobolizerCrawler () {
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(false);
}
public void fillTextBoxWithUrl(String vacancyURL) throws IOException {
final HtmlPage page = webClient.getPage(jobolizerUrl);
System.out.println(page.asText());
final HtmlForm form = page.getFirstByXPath("//form[@action='/phpProxy/getJOBolizerResponse_en.php']");
final HtmlTextInput input = form.getInputByName("url");
input.setText(vacancyURL);
HtmlButton button = (HtmlButton) page.getByXPath("/form[@action='/phpProxy/getJOBolizerResponse_en.php']/a[@id=lightboxlink]").get(0);
HtmlPage page2 = button.click();
String page2Text = page2.asText();
System.out.println(page2Text);
}
}
Share
edited Sep 14, 2014 at 10:37
PBA
asked Sep 12, 2014 at 14:48
PBAPBA
4252 gold badges9 silver badges25 bronze badges
1 Answer
Reset to default 6I figured it out, here is working code:
HtmlAnchor link = null;
for (HtmlAnchor anchor : anchors) {
String str = anchor.asText();
if (anchor.asText().equals("Start"))
link = anchor;
}
HtmlPage page2 = link.click();