URLConnection con = google.openConnection();
con.setRequestProperty("User-Agent", "");
InputStream in = con.getInputStream();
try {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
kit.read(new InputStreamReader(in, "UTF-8"), doc, 0);
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
if(it.getAttributes() != null) {
String href = (String) it.getAttributes().getAttribute(HTML.Attribute.HREF);
if (href != null && href.endsWith("." + currentFiletype)) {
URL url = new URL(new URL("http", "www.google.com", "dummy"), href);