映画のリストをクロールして、データベースに保存しました。英語の文字のみを含む映画ではすべて問題なく動作しますが、問題は、英語以外の文字を含む映画の名前の一部が正しく表示されないことです。たとえば、イタリア映画「Il più Crudle dei giorni」は「Il più Crudle dei giorni」として保存されます。
解決策があれば誰か親切に教えてもらえますか?(クローラーの言語を設定できることはわかっています。すでにイタリア語の映画タイトルもクロールしましたが、英語のタイトルをクロールしたい場合でも、Imdb には英語以外の文字を含む映画がいくつかあります)
編集:ここに私のコードがあります:
String baseUrl = "http://www.imdb.com/search/title?at=0&count=250&sort=num_votes,desc&start="+start+"&title_type=feature&view=simple";
label1: try {
org.jsoup.Connection con = Jsoup.connect(baseUrl).userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21").header("Accept-Language", "en");
con.timeout(30000).ignoreHttpErrors(true).followRedirects(true);
Response resp = con.execute();
Document doc = null;
if (resp.statusCode() == 200) {
doc = con.get();
Elements myElements = doc.getElementsByClass("results").first().getElementsByTag("table");
Elements trs = myElements.select(":not(thead) tr");
for (int i = 0; i < trs.size(); i++) {
Element tr = trs.get(i);
Elements tds = tr.select("td");
for (int j = 3; j < tds.size(); j++) {
Elements links = tds.select("a[href]");
String titleId = links.attr("href");
String movietitle = links.html();
//I ADDED YOUR CODE HERE
Charset c = Charset.forName("UTF-16BE");
ByteBuffer b = c.encode(movietitle);
for (int m = 0; b.hasRemaining(); m++) {
int charValue = (b.get()) & 0xff;
System.out.print((char) charValue);
}
// try{
// String query = "INSERT into test (movieName,ImdbId)" + "VALUES (?,?)";
// PreparedStatement preparedStmt = conn.prepareStatement(query);
// preparedStmt.setString (1, movietitle);
// preparedStmt.setString (2, titleId );
// }catch (Exception e)
// {
// e.printStackTrace();
// }
ありがとう、