Java Web Crawler Libraries

2019-02-01 05:51发布

I wanted to make a Java based web crawler for an experiment. I heard that making a Web Crawler in Java was the way to go if this is your first time. However, I have two important questions.

  1. How will my program 'visit' or 'connect' to web pages? Please give a brief explanation. (I understand the basics of the layers of abstraction from the hardware up to the software, here I am interested in the Java abstractions)

  2. What libraries should I use? I would assume I need a library for connecting to web pages, a library for HTTP/HTTPS protocol, and a library for HTML parsing.

11条回答
手持菜刀,她持情操
2楼-- · 2019-02-01 06:21

You can explore.apache droid or apache nutch to get the feel of java based crawler

查看更多
趁早两清
3楼-- · 2019-02-01 06:23

I recommend you to use the HttpClient library. You can found examples here.

查看更多
虎瘦雄心在
4楼-- · 2019-02-01 06:26

For parsing content, I'm using Apache Tika.

查看更多
该账号已被封号
5楼-- · 2019-02-01 06:29

I think jsoup is better than others, jsoup runs on Java 1.5 and up, Scala, Android, OSGi, and Google App Engine.

查看更多
做个烂人
6楼-- · 2019-02-01 06:38

Here is a list of available crawler:

https://java-source.net/open-source/crawlers

But I suggest using Apache Nutch

查看更多
女痞
7楼-- · 2019-02-01 06:40

This is How your program 'visit' or 'connect' to web pages.

    URL url;
    InputStream is = null;
    DataInputStream dis;
    String line;

    try {
        url = new URL("http://stackoverflow.com/");
        is = url.openStream();  // throws an IOException
        dis = new DataInputStream(new BufferedInputStream(is));

        while ((line = dis.readLine()) != null) {
            System.out.println(line);
        }
    } catch (MalformedURLException mue) {
         mue.printStackTrace();
    } catch (IOException ioe) {
         ioe.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            // nothing to see here
        }
    }

This will download source of html page.

For HTML parsing see this

Also take a look at jSpider and jsoup

查看更多
登录 后发表回答