根据isbn查询图书信利用豆瓣的API

String apikey = "111111111111111111111111111111";
String isbnUrl = "http://api.douban.com/book/subject/isbn/";

public static void main(String[] args) throws Exception {
 //requestUrl = isbnUrl + isbnNo + "?apikey=" + apikey;
 //eg:http://api.douban.com/book/subject/isbn/9787111298854?apikey=111111111111111111114
 ISBN isbnTest = new ISBN();
 String isbnNo = "9787111298854";
 String xml = isbnTest.fetchBookInfoByXML(isbnNo);
 System.out.println(xml);
}

/**
 * 从根据isbn号从豆瓣获取数据。已经申请apikey,每分钟最多40次请求,足够用。
 * @param isbnNo
 * @return
 * @throws IOException
 */
public String fetchBookInfoByXML(String isbnNo) throws IOException {
 String requestUrl = isbnUrl + isbnNo + "?apikey=" + apikey;
 URL url = new URL(requestUrl);
 URLConnection conn = url.openConnection();
 InputStream is = conn.getInputStream();
 InputStreamReader isr = new InputStreamReader(is, "utf-8");
 BufferedReader br = new BufferedReader(isr);
 StringBuilder sb = new StringBuilder();

 String line = null;
 while ((line = br.readLine()) != null) {
 sb.append(line);
 }

 br.close();
 return sb.toString();
}

未经允许不得转载:SuperMan's blog » 根据isbn查询图书信利用豆瓣的API

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址