我是java编程的新手。我正在编写一个程序/应用程序,用一个用户给出的关键字一次查询yahoo,bing和hotbot。我想在一个页面中完全显示结果URL。但我只能发送查询并将生成的html代码保存在记事本文件中。 html文档中有很多垃圾和广告。如何从搜索结果中仅获取生成的URL并显示它们?
我做了这么多:
package linker;
import java.net.*;
import java.io.*;
import java.util.*;
public class Linker {
public static void main(String[] args) throws MalformedURLException, IOException {
URL url = new URL("http://en.wikipedia.org/wiki/India");
HttpURLConnection connect = (HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
connect.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
in.close();
}
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("outputfile.txt"));
String inputLine;
while ((inputLine = in.readLine()) != null){
try{
writer.write(inputLine);
}
catch(IOException e){
e.printStackTrace();
return;
}
}
in.close();
writer.close();
String inputline;
BufferedReader br = new BufferedReader(new FileReader (newFile("out.txt")));
while ((inputline = br.readLine()) != null)
{
System.out.println(inputline);
}
}
}package linker;
import java.net.*;
import java.io.*;
import java.util.*;
public class Linker {
public static void main(String[] args) throws MalformedURLException, IOException {
URL url = new URL("http://en.wikipedia.org/wiki/India");
HttpURLConnection connect = (HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
connect.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
in.close();
}
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("outputfile.txt"));
String inputLine;
while ((inputLine = in.readLine()) != null){
try{
writer.write(inputLine);
}
catch(IOException e){
e.printStackTrace();
return;
}
}
in.close();
writer.close();
String inputline;
BufferedReader br = new BufferedReader(new FileReader (newFile("out.txt")));
while ((inputline = br.readLine()) != null)
{
System.out.println(inputline);
}
}
}package linker;
import java.net.*;
import java.io.*;
import java.util.*;
public class Linker {
public static void main(String[] args) throws MalformedURLException, IOException {
URL url = new URL("http://en.wikipedia.org/wiki/India");
HttpURLConnection connect = (HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
connect.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
in.close();
}
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("outputfile.txt"));
String inputLine;
while ((inputLine = in.readLine()) != null){
try{
writer.write(inputLine);
}
catch(IOException e){
e.printStackTrace();
return;
}
}
in.close();
writer.close();
String inputline;
BufferedReader br = new BufferedReader(new FileReader (newFile("out.txt")));
while ((inputline = br.readLine()) != null)
{
System.out.println(inputline);
}
}
}package linker;
import java.net.*;
import java.io.*;
import java.util.*;
public class Linker {
public static void main(String[] args) throws MalformedURLException, IOException {
URL url = new URL("http://en.wikipedia.org/wiki/India");
HttpURLConnection connect = (HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
connect.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
in.close();
}
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("outputfile.txt"));
String inputLine;
while ((inputLine = in.readLine()) != null){
try{
writer.write(inputLine);
}
catch(IOException e){
e.printStackTrace();
return;
}
}
in.close();
writer.close();
String inputline;
BufferedReader br = new BufferedReader(new FileReader (newFile("out.txt")));
while ((inputline = br.readLine()) != null)
{
System.out.println(inputline);
}
}
}