我制作了这个示例以通过 java 应用程序请求一个 url 查询。请求连接和查询是对的。但是,我错过了如何从查询中获取所有 href 元素并写入一个输出文件?有人有任何指导方针吗?
提前致谢
Document engineSearch=Jsoup.connect("http://ask.com/web?q="+URLEncoder.encode(query))
.userAgent("Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.8.1.6) Gecko/20070723 Iceweasel/2.0.0.6 (Debian-2.0.0.6-0etch1)")
.get();
String title = engineSearch.title();
Elements links = engineSearch.select("a[href]").first().getAllElements();
String queryEncoding=engineSearch.outputSettings().charset().name();
file = new File(folder.getPath()+"\\"+date+" "+Tag+".html");
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file),queryEncoding);
writer.write(engineSearch.html());
writer.close();