私は現在、テキストのみを含み、すべて同じ方法でフォーマットされている、非常によく似た多数の Web サイトにアクセスしようとしています。
このメソッドを呼び出す最初の 5 ~ 30 回は機能しますが、その後は null が返されます。エラーなし。文字列を取得できない理由はありますか?
少しテキストを挿入した後、ランダムに のように見え、文字列グラブの本文をスキップすることline = in.readLine()
がわかりました。null
あまり使わないBufferedReader
ので、それが問題かもしれません。ヒントや、これをトラブルシューティングできる方法があれば、大歓迎です。
public static String pullString(int id) throws IOException {
String price;
logError("Checkpoint 1");
URL url = new URL("example.com");
URLConnection con = url.openConnection();
logError("Checkpoint 2");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
logError("Checkpoint 3");
String line;
while ((line = in.readLine()) != null) {
// ^ for some reason this becomes null, but on identical pages it works fine.
//Removed unneeded info
return ---;
} catch (NumberFormatException e) {
logError("NumberFormatException");
return null;
}
}
}
logError("left out the back");
return null;
}