Não estou conseguindo recuperar um elemento por id usando o Jsoup, caso a imagem do captcha. Estou tentando automatizar a busca de veiculos no site do detran de SP
http://denatran.serpro.gov.br/certificado/veiculo.asp
Segue código:
try {
Connection conn = Jsoup.connect("http://denatran.serpro.gov.br/certificado/veiculo.asp");
Document d = conn.get();
Element captcha = d.getElementById("img_captcha_serpro_gov_br");
if (captcha == null) {
throw new RuntimeException("Unable to find captcha...");
}
Connection.Response response = Jsoup //
.connect(captcha.absUrl("src")) // Extract image absolute URL
.cookies(conn.response().cookies()) // Grab cookies
.ignoreContentType(true) // Needed for fetching image
.execute();
ImageIcon image = new ImageIcon(ImageIO.read(new ByteArrayInputStream(response.bodyAsBytes())));
JOptionPane.showMessageDialog(null, image, "Captcha image", JOptionPane.PLAIN_MESSAGE);
} catch (IOException ex) {
System.err.println(ex);
}
