java网络爬虫爬取网站代码
package Demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class WebSpiderTest {
public static void main(String[] args) {
try {
URL url = new URL("http://www.163.com");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String temp =" ";
while((temp=reader.readLine())!=null) {
System.out.println(temp);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
j
}
}
将上一个代码进行封装
package Demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import ja