Crawler funktioniert in intellij aber in Eclipse nicht

doktordoom

Mitglied
Guten Abend,
ich habe mir einen Crawler gebaut. Dieser soll von der Google List alle Wiki links, zu einem bestimmten KeyValue/Anfrage finden.
Sind die links gefunden werden die websiten lokal gespeichert. Im intellij funktioniert alles wie gewollt, leider im Eclipse nicht.
Ich habe die klasse einfach importiert. Nach vier Google hyperlinks bricht die Suche ab.

Java:
package example.jdbc.movies;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * This class is used get links from HTML using Jsoup.
 * @author w3spoint
 */
public class Crawler {

    public static String KeyValue ="Pink";

    public static URL LastUrl;

    public static void DownloadWebPage(URL urlwebpage, int Linkcount) throws IOException { // wichtig nur drei websiten storen
        try {
            System.out.println("Link: " + urlwebpage);
            // Create URL object

            BufferedReader readr =
                    new BufferedReader(new InputStreamReader(urlwebpage.openStream()));

            // Enter filename in which you want to download
            BufferedWriter writer =
                    new BufferedWriter(new FileWriter(Linkcount+KeyValue+"Download.html"));

            // read each line from stream till end
            String line;
            while ((line = readr.readLine()) != null) {
                writer.write(line);
            }

            readr.close();
            writer.close();
            System.out.println("Website Successfully Downloaded.");
            LastUrl = urlwebpage;
        }

        // Exceptions
        catch (MalformedURLException mue) {
            System.out.println("Malformed URL Exception raised");
        }
        catch (IOException ie) {
            System.out.println("IOException raised");
        }
    }

    public static void getWikisidefromGoogle()
    {
        Document document;
        int Linkscount = 0;
        try {
            //Get Document object after parsing the html from given url.
            document = Jsoup.connect("https://www.google.co.in/search?q="+KeyValue+"&num=3").get();

            InputStream is = null;
            //Get links from document object.
            Elements links = document.select("a[href]");

            //Iterate links and print link attributes.
            for (Element link : links) {
                if(link.attr("href").contains("wikipedia")) {
                    URL url = new URL(link.attr("href")); // create an new url
                    if(!url.equals(LastUrl)) {
                        DownloadWebPage(url, Linkscount);
                        Linkscount++;
                        if (Linkscount == 3)
                            break;
                    }
                }


            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    public static void main(String args[]){
        getWikisidefromGoogle();
    }
}
 
Hi @M.L. ,
ich habe eben das Projekt einfach im Eclipse importiert und nochmal ausgeführt. Darauf hin habe ich wie im Bild zu sehen das selbe Ergebnis erhalten. Darunter siehst das Ergebnis von intellij.

eclipse-crawler.png






intellij-crawler.png
 

Zurück
Oben