java - Problem with crawling images?
天蓬老师
天蓬老师 2017-06-23 09:12:30
0
1
835

Just modified POM, you can download the source code again

This is the project address of the crawler I wrote
The project does not report an error, but the problem is that after downloading the image to the local area, the image is often incomplete, as follows:

##This is the core code for downloading pictures, as follows:

@Override
    public void run() {
        Response res = null;
        try {
            res = Jsoup.connect(src).ignoreContentType(true).timeout(30000).execute();
            byte[] bytes = res.bodyAsBytes();
            File file = new File(path + name);
            if (!file.exists()) {
                RandomAccessFile raf = new RandomAccessFile(file, "rw");
                raf.write(bytes);
                raf.close();
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }

After data query, I feel that it is a problem with the range request

Range or a problem that I did not find? I hope you can take a look at it, thank you

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
typecho
  1. It seems that the response data is not complete. You can debug it to see if there is any discrepancy between the actual data size of the response and the data size you saved.

  2. Or maybe because there is still some data in the buffer and there is no time to write to the file, the process exits at this time, resulting in incomplete data. Perform a flush operation before closing the file stream.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template