POM
, you can download the source code againThis 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:
@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
typecho2017-06-23 09:14:30
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.
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.