写爬虫和用Java写爬虫的区别是什么

更新时间:02-02 教程 由 静谧 分享

写爬虫和用Java写爬虫的区别是什么?

没得区别的,用Java写爬虫代码

public class DownMM {

public static void main(String[] args) throws Exception {

//out为输出的路径,注意要以\\结尾

String out = "D:\\JSP\\pic\\java\\";

try{

File f = new File(out);

if(! f.exists()) {

f.mkdirs();

}

}catch(Exception e){

System.out.println("no");

}

String url = "http://www.mzitu.com/share/comment-page-";

Pattern reg = Pattern.compile("

for(int j=0, i=1; i<=10; i++){

URL uu = new URL(url+i);

URLConnection conn = uu.openConnection();

conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko");

Scanner sc = new Scanner(conn.getInputStream());

Matcher m = reg.matcher(sc.useDelimiter("\\A").next());

while(m.find()){

Files.copy(new URL(m.group(1)).openStream(), Paths.get(out + UUID.randomUUID() + ".jpg"));

System.out.println("已下载:"+j++);

}

}

}

}

声明:关于《写爬虫和用Java写爬虫的区别是什么》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2314786.html