I'm trying to fetch this page (it's in Chinese, sorry for that):
amazon(dot)cn/s?rh=n:663227051
using the following code:
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class Application {
public static void main(String[] args) throws IOException, InterruptedException {
final URL url = new URL("http://www.amazon.cn/s?rh=n:663227051");
final String agentString = "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)";
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("User-Agent", agentString);
InputStreamReader streamReader = new InputStreamReader(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(streamReader);
final String path = "d:\\desktop\\Test.html";
FileWriter writer = new FileWriter(path);
writer.write("");
String line;
while ((line = reader.readLine()) != null)
writer.append(line).append(System.getProperty("line.separator"));
writer.close();
}
}
But after running this code for several times, I found that I randomly get two different results (see screenshots here http://www.flickr.com/photos/31629891@N07/4173636464/)
No matter how many times I refresh this page in browser, it returns the same result.
I'm wondering why is this so?