在单个程序中同时抓取多个网站

时间:2014-08-25 16:52:21

标签: java

1.如何在单个程序中同时抓取2个以上的站点 2.如何在实施的Runnabkle类中获取inUrl

1.List inUrl = new ArrayList();

    System.out.println("Numof url");
    final int urlSize=scanner.nextInt();
    int count =0;
    while (count < urlSize) {
        System.out.println("Enter Name of url");
    inUrl.add(scanner.next());
        count++;
    }

  ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);

  for (int i = 0; i < inUrl.size(); i++) {
    //System.out.println();
      System.out.println(inUrl.get(i));
      Runnable worker = new MyRunnable(inUrl.get(i));
        executor.execute(worker);
        executor.shutdown();
    2.public static class MyRunnable implements Runnable {
    public String inUrl;
   int s;
    int urlSize=s;
 List<String> Url;
  public  MyRunnable(String inUrl) {
        this.inUrl = inUrl;
    }
  3.how to repeat  the crawling for Multiplesites in run method

0 个答案:

没有答案